Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7291

Primitive variables with no initial value expression not given default value when referenced within a closure

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.8.6, 2.2.1, 2.4.0
    • Fix Version/s: 2.4.8
    • Component/s: None
    • Labels:
      None
    • Environment:
      Windows 8.1, JDK 1.7_71 and 1.8_25

      Description

      I have problem with following code:

      double a;
      def b = {
         a = a + 1;
      }
      b();
      

      I tried to compile it with groovy 1.8.6 and it worked
      variable 'a' was instantiated with value 0.0

      but after upgrade to groovy 2.2.1
      it throws NullPointerException because variable 'a' is instantiated to null

      I tried to decompile class files and declaration of 'a' looked like this:
      version 1.8.6

      CallSite[] var1 = $getCallSiteArray();
              final Reference a = new Reference((Double)DefaultTypeTransformation.box(0.0D));
              DefaultTypeTransformation.doubleUnbox(a.get());
      ...
      

      version 2.2.1

      CallSite[] var1 = $getCallSiteArray();
      final Reference a = new Reference((Object)null);
      Double var10000 = (Double)a.get();
      ...
      

      I tried it also with version 2.4.0 but it has same result as 2.2.1
      In attachment are groovy classes, compiled classes and consoleOutputs for versions 1.8.6 and 2.2.1

        Attachments

        1. groovyBug.zip
          10 kB
          David Richter

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              d.richter David Richter
            • Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: