On 29.05.20 03:39, harada.tomokazu....@jp.nssol.nipponsteel.com wrote:
Dear All,

I noticed that GroovySunClassLoader and SunClassLoader are broken.

I tried to use a Groovy script in Java and noticed that 
GroovySunClassLoader.sunVM was null.
I'm using OpenJDK 8u252 and it has sun.reflect.MagicAccessorImpl, so 
GroovySunClassLoader.sunVM should not be null.

[...]
I applied the above fix to Groovy and ran the following test program, but the 
test failed.
-----------------------------
package app;

import groovy.lang.GroovyShell;
import org.codehaus.groovy.runtime.callsite.GroovySunClassLoader;

public class Main {
     public static void main(String[] args) {
         System.out.println("sunVM: " + GroovySunClassLoader.sunVM);
         GroovyShell shell = new GroovyShell();
         String name = (String) shell.evaluate("new app.Main().getName()");
         System.out.println(name);
     }

     private String getName() {
         return "abc";
     }
}
-----------------------------

this means you want the Groovy program to access the private method a
Java class, right?

The output of the test program:

sunVM: org.codehaus.groovy.runtime.callsite.GroovySunClassLoader@27bc2616
Exception in thread "main" java.lang.IllegalAccessError: tried to access method 
app.Main.getName()Ljava/lang/String; from class app.Main$getName
     at app.Main$getName.call(Unknown Source)
     at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
     at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
     at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
     at Script1.run(Script1.groovy:1)
     at groovy.lang.GroovyShell.evaluate(GroovyShell.java:427)
     at groovy.lang.GroovyShell.evaluate(GroovyShell.java:461)
     at groovy.lang.GroovyShell.evaluate(GroovyShell.java:436)
     at app.Main.main(Main.java:11)

IllegalAccessError seems to occur as MagicAccessorImpl is not effective.

Does MagicAccessorImpl prevent access checks? It does prevent bytecode
verification, which allows us to load the generated class faster.

But I don't think that this access check falls under the magic as well.
Groovy should have accessed by reflection only instead in non-indy mode.

Could you please tell us the version of Groovy you are using as well?

bye Jochen

Reply via email to