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.

       

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

          Mark Waite added a comment -

          Are you really using remoting 2.34? That was released in 2013. The current release of the remoting jar is remoting-4.7 per https://github.com/jenkinsci/remoting/releases/tag/remoting-4.7

          Remoting has been running with Java 11 for over a year, possibly over two years now.

          Mark Waite added a comment - Are you really using remoting 2.34? That was released in 2013. The current release of the remoting jar is remoting-4.7 per https://github.com/jenkinsci/remoting/releases/tag/remoting-4.7 Remoting has been running with Java 11 for over a year, possibly over two years now.

          Jeff Thompson added a comment -

          If the version is correct, then it definitely isn't supported. Otherwise, we'll probably need more information about the scenario to understand what distinguishes this from other, known working ones.

          Jeff Thompson added a comment - If the version is correct, then it definitely isn't supported. Otherwise, we'll probably need more information about the scenario to understand what distinguishes this from other, known working ones.

          Saptarshi added a comment -

          Hello, I have update the the version to 4.7 still facing the same issue.

          On analysing the remoting source code found that the hudson.remoting.Launcher.addClasspath invokes URLClassLoader and passes the instance using ClassLoader.getSystemClassLoader().
          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".

          Saptarshi added a comment - Hello, I have update the the version to 4.7 still facing the same issue. On analysing the remoting source code found that the hudson.remoting.Launcher.addClasspath invokes URLClassLoader and passes the instance using ClassLoader.getSystemClassLoader(). 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".

          Oleg Nenashev added a comment -

          Oleg Nenashev added a comment - https://github.com/jenkinsci/remoting/pull/443  is under review

            Unassigned Unassigned
            saptarshi1991 Saptarshi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: