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

Error occurred when accessing static field in lambda within static initialization block

    XMLWordPrintableJSON

Details

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

    Description

      The following test failed due to accessing static field one

      @groovy.transform.CompileStatic
      class Test1 {
          static sl
          static int one = 1
          static { sl = [1, 2, 3].stream().map(e -> e + one).toList() }
      }
      
      assert [2, 3, 4] == Test1.sl
      
      java.lang.ExceptionInInitializerError
      
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      
      	at ConsoleScript2.run(ConsoleScript2:8)
      
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      
      Caused by: java.lang.ClassCastException: class Test1$__clinit__lambda1 cannot be cast to class Test1 (Test1$__clinit__lambda1 and Test1 are in unnamed module of loader groovy.lang.GroovyClassLoader$InnerLoader @f055fc9)
      
      	at Test1$__clinit__lambda1.doCall(ConsoleScript2:5)
      
      	at Test1.<clinit>(ConsoleScript2:5)
      
      	... 7 more
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              daniel_sun Daniel Sun
              Votes:
              0 Vote for this issue
              Watchers:
              2 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