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

Created a class loader that override loadClass can calls protected methods results in VerifyError

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.6
    • 2.5.0-alpha-1
    • 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()
      

      Attachments

        Activity

          People

            jwagenleitner John Wagenleitner
            graemerocher1 Graeme Rocher
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: