codeconsole opened a new pull request, #3252:
URL: https://github.com/apache/groovy/pull/3252

   In dynamic and `@TypeChecked` code, a package-private field of a superclass 
with the same package name but of another class loader, such as a class of an 
earlier parse of the same `GroovyShell`, is reached through the meta-class by 
`f` and `this.f`. The forms that go directly to the field fail:
   
   ```groovy
   // first parse
   package p
   class F { @PackageScope String pf = 'pf' }
   
   // second parse with the same GroovyShell
   package p
   class C extends F {
       def test() {
           super.pf            // IllegalAccessError, as are super.@pf and 
this.@pf
           this.@pf = 'w'      // and writes through them
       }
   }
   ```
   
   4.0.32, 5.0.8 and 6.0.0 fail the same way. 
`AsmClassGenerator.visitPropertyExpression` and `visitAttributeExpression` 
decide by the package name and write `GETFIELD` or `PUTFIELD`. They now leave 
such a field to the meta-class in dynamic code, using `isInSameRuntimePackage`, 
which only knows the case for an in-memory compilation of a `GroovyClassLoader`.
   
   Static compilation is unchanged: it does not select a member at run time. 
#3097 (GROOVY-12568) reports such an access there. A protected field, which a 
subclass can use directly, and a field of the same compilation are still 
accessed directly.
   
   This and #3097 add an import next to each other in `AsmClassGenerator`; 
whichever lands second keeps both.
   
   ## Compatibility
   
   Code that failed with `IllegalAccessError` now works.
   
   ## Tests
   
   `DynamicFieldOfAnotherRuntimePackageTest`: 
`testReadOfPackagePrivateFieldOfSuperclass` and 
`testWriteOfPackagePrivateFieldOfSuperclass`, each dynamic and `@TypeChecked`, 
fail without the change. The other tests pin what must not change: closures, a 
protected field and a field of the same compilation stay as they are, and 
static compilation still fails at run time without #3097. The 
`org.codehaus.groovy.classgen.asm.sc`, `groovy.transform.stc` and `gls` tests 
pass, apart from the two `testSelfReferentialTypeParameter5` tests, whose 
`@Grab` of netty did not resolve on my network. The Checkstyle and CodeNarc 
gates pass.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to