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

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      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.

       

        Attachments

          Activity

          saptarshi1991 Saptarshi created issue -
          saptarshi1991 Saptarshi made changes -
          Field Original Value New Value
          Description I am getting the following error after updating to jdk11.

           
          {code:java}
          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){code}
           

          On analysing the remoting source code found that the hudson.remoting.Launcher.addClasspath invokes URLClassLoader and passes the instance using ClassLoader.getSystemClassLoader().
          {code:java}
          $addURL.invoke(ClassLoader.getSystemClassLoader(),new File(token).toURI().toURL());{code}
          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
          {code:java}
          $addURL.invoke(URLClassLoader.newInstance(urls),new File(token).toURI().toURL());{code}
          This resolved the issue.

          Kindly verify if this approach is apt.

           
          I am getting the following error after updating to jdk11.
          {code:java}
          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){code}
          On analysing the remoting source code found that the hudson.remoting.Launcher.addClasspath invokes URLClassLoader and passes the instance using ClassLoader.getSystemClassLoader().
          {code:java}
          $addURL.invoke(ClassLoader.getSystemClassLoader(),new File(token).toURI().toURL());{code}
          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
          {code:java}
          $addURL.invoke(URLClassLoader.newInstance(urls),new File(token).toURI().toURL());{code}
          This resolved the issue.

          Kindly verify if this approach is apt.

           
          saptarshi1991 Saptarshi made changes -
          Summary Exception in hudson.remoting.Launcher:-object is not an instance of declaring class Dynamic Class Loading Fails In Reflection.Exception in hudson.remoting.Launcher:-object is not an instance of declaring class
          oleg_nenashev Oleg Nenashev made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          oleg_nenashev Oleg Nenashev made changes -
          Status In Progress [ 3 ] In Review [ 10005 ]

            People

            Assignee:
            jthompson Jeff Thompson
            Reporter:
            saptarshi1991 Saptarshi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated: