Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.6
-
None
-
None
Description
The following script results in a VerifyError:
java.lang.VerifyError: (class: FooClassLoader, method: loadClass signature: (Ljava/lang/String;Z)Ljava/lang/Class;) Bad access to protected data at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) at java.lang.Class.getDeclaredConstructors(Class.java:2020) at org.codehaus.groovy.reflection.CachedClass$2$1.run(CachedClass.java:77) at java.security.AccessController.doPrivileged(Native Method) at org.codehaus.groovy.reflection.CachedClass$2.initValue(CachedClass.java:74) at org.codehaus.groovy.reflection.CachedClass$2.initValue(CachedClass.java:72) at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:49) at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:36) at org.codehaus.groovy.reflection.CachedClass.getConstructors(CachedClass.java:271) at groovy.lang.MetaClassImpl.<init>(MetaClassImpl.java:220)
It should fail with a compilation error since the `loadClass` method is protected.
import groovy.transform.* @CompileStatic class FooClassLoader extends URLClassLoader { protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { try { return super.loadClass(name, resolve) } catch (ClassNotFoundException cnfe) { return ClassLoader.systemClassLoader.loadClass(name, resolve) } } } def cl = new FooClassLoader()