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

Compilation error when accessing package-private super class field using `this` from inside a closure

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.8, 3.0.0-rc-1
    • Fix Version/s: 3.0.0-rc-2
    • Component/s: Static compilation
    • Labels:
      None

      Description

      Compilation fails when accessing a package-private super class field from inside a closure:

      // error message:  java.lang.IllegalAccessError: class a.ConcreteClass$_doThing_closure1 tried to access field a.Abstract_Class.superField (a.ConcreteClass$_doThing_closure1 is in unnamed module of loader groovy.lang.GroovyClassLoader$InnerLoader @5fa47fea; a.Abstract_Class is in unnamed module of loader groovy.lang.GroovyClassLoader$InnerLoader @28cda624)
      
             GroovyShell shell = new GroovyShell()
              shell.evaluate('''
                  package a
                  
                  import groovy.transform.CompileStatic
                  
                  @CompileStatic
                  abstract class Abstract_Class {
                      @groovy.transform.PackageScope String superField = 'field'
                      
                      abstract String doThing()
                  }
                  assert true
              ''')
      
              shell.evaluate('''
                  package a
                  
                  import a.Abstract_Class
                  import groovy.transform.CompileStatic
                  
                  @CompileStatic
                  class ConcreteClass extends Abstract_Class {
                     
                      @Override
                      String doThing() {
                          this.with {
                              return this.superField
                          }
                      }
                  }
                  assert true
              ''')
      
              shell.evaluate("assert new a.ConcreteClass().doThing() == 'field'")
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                emilles Eric Milles
                Reporter:
                daniel_sun Daniel Sun
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: