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

SC: Lambda in static initializer that uses static field on LHS of += produces errors

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.0-rc-2
    • 3.0.0-rc-3
    • None
    • None

    Description

      Follow up to GROOVY-9332 and GROOVY-9333. Consider the following:

      @groovy.transform.CompileStatic
      class Test1 {
          static int acc = 1
          static { [1, 2, 3].forEach((Integer i) -> acc += i) }
      }
      assert Test1.acc == 7
      
      java.lang.ExceptionInInitializerError\r\n
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n
      	at java.lang.reflect.Method.invoke(Method.java:498)\r\n
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              emilles Eric Milles
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10m
                  10m