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

parsing bug when inner class references top level class fields in groovy 3

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.6, 3.0.7
    • 3.0.8, 4.0.0-alpha-3
    • None
    • None

    Description

      The follow code compiles fine under groovy 2 but does not compile under groovy 3

      import groovy.transform.CompileStatic
      
      import java.awt.Color
      import java.awt.event.MouseAdapter
      import java.awt.event.MouseEvent
      
      @CompileStatic
      public class TreePair2 {
      
          int clickCount = 0;
          boolean isAprilFools = false;
      
          private TreePair2() {
          }
      
          protected class TreeMouseClickHandler extends MouseAdapter {
      
              @Override
              public void mouseClicked(MouseEvent e) {
                  if(isAprilFools) {
                      clickCount++;
                  }
              }
          }
      }
      

      Error msg:

      Exception thrown
      
      groovy.lang.GroovyRuntimeException: ASM reporting processing error for TreePair2$TreeMouseClickHandler#mouseClicked with signature void mouseClicked(java.awt.event.MouseEvent) in ConsoleScript77:18. ConsoleScript77
      	at jdk.internal.reflect.GeneratedMethodAccessor56.invoke(Unknown Source)
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
      	at groovyjarjarasm.asm.Frame.merge(Frame.java:1268)
      	at groovyjarjarasm.asm.Frame.merge(Frame.java:1244)
      	at groovyjarjarasm.asm.MethodWriter.computeAllFrames(MethodWriter.java:1610)
      	at groovyjarjarasm.asm.MethodWriter.visitMaxs(MethodWriter.java:1546)
      	... 2 more

      The problem seems to be with these 3 lines

                  if(isAprilFools) {
                      clickCount++;
                  }
      

      if you just have

      if(isAprilFools) { 
        println(1) 
      }
      // it works
      
      // or just
      clickCount++;
      // also works
      
      // but when you add clickCount++ into the if statement, it fails
      

      I also want to note that by removing staticcompilation, it seems to work.

      Attachments

        Activity

          People

            Unassigned Unassigned
            howardzzhang Howard
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: