Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-65046

Dynamic Class Loading Fails In Reflection.Exception in hudson.remoting.Launcher:-object is not an instance of declaring class


    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • remoting
    • jdk-11.0.10.jdk, remoting-2.34.jar

      I am getting the following error after updating to jdk11.

      Exception in thread "main" java.lang.IllegalArgumentException: object is not an instance of declaring class
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      at hudson.remoting.Launcher.addClasspath(Launcher.java:129)

      On analysing the remoting source code found that the hudson.remoting.Launcher.addClasspath invokes URLClassLoader and passes the instance using ClassLoader.getSystemClassLoader().

      $addURL.invoke(ClassLoader.getSystemClassLoader(),new File(token).toURI().toURL());

      However in java 11, this seems like an illegal operation as ClassLoader.getSystemClassLoader() does not get the instance of  URLClassLoader due to which we are getting the error "object is not an instance of declaring class".

      To fix this issue what I have updated the addClasspath to invoke the URLClassLoader using a new instance of the class

      $addURL.invoke(URLClassLoader.newInstance(urls),new File(token).toURI().toURL());

      This resolved the issue.

      Kindly verify if this approach is apt.


            Unassigned Unassigned
            saptarshi1991 Saptarshi
            0 Vote for this issue
            4 Start watching this issue