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

    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.

           
          markewaite 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.

          markewaite 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.
          jthompson 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.

          jthompson 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.
          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
          saptarshi1991 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".

          saptarshi1991 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 Oleg Nenashev made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          oleg_nenashev Oleg Nenashev made changes -
          Status In Progress [ 3 ] In Review [ 10005 ]
          oleg_nenashev Oleg Nenashev added a comment - https://github.com/jenkinsci/remoting/pull/443  is under review
          markewaite Mark Waite made changes -
          Assignee Jeff Thompson [ jthompson ]

          People

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

            Dates

              Created:
              Updated: