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

MissingMethodException ClassCastException because of plugin classloader

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • Jenkins 2.361.4
      Pipeline Utility Steps Version 2.13.2

      This ticket intends to regroup different issues about the same root cause: because of Jenkins plugin classloader isolation, we cannot create instance of plugin Classes, unless we do reflectivity.

       

      https://issues.jenkins.io/browse/JENKINS-40432

      https://issues.jenkins.io/browse/JENKINS-48052

      https://issues.jenkins.io/browse/JENKINS-56975

      have the same root cause.

       

      How to reproduce the issue:

      Create a pipeline job with this content:

       

      node {
          writeFile(file: "pom.xml", text: "<project></project >")
          pom = readMavenPom(file: 'pom.xml')
          dep = new Dependency()
          dep.setArtifactId("artifactId")
          pom.addDependency(dep)
      } 

       

       

      Current behavior:

      The job is in error:

       

      hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.apache.maven.model.Model.addDependency() is applicable for argument types: (org.apache.maven.model.Dependency) values: [Dependency {groupId=null, artifactId=artifactId, version=null, type=jar}]
      Possible solutions: addDependency(org.apache.maven.model.Dependency)
      The following classes appear as argument class and as parameter class, but are defined by different class loader:
      org.apache.maven.model.Dependency (defined by 'jenkins.util.URLClassLoader2@a0eb06d' and 'jenkins.util.URLClassLoader2@47f54404')
      If one of the method suggestions matches the method you wanted to call, 
      then check your class loader setup.

      Expected content:

       

      Job in success.

      Cause:

      The Dependency in main classloader is not instantiated from the same Class as in the plugin classloader.

      Workaround:

      node {
          writeFile(file: "pom.xml", text: "<project></project >")
          pom = readMavenPom(file: 'pom.xml')
          //dep = new Dependency()
          dep = pom.&addDependency.parameterTypes[0].newInstance()
          dep.setArtifactId("artifactId")
          pom.addDependency(dep)
      } 

      This does reflectivity and creates a new instance from the Class of plugin classloader. However this cause a security alert and we need to approve some methods like newInstance() on Jenkins security board.

       

       

            rsandell rsandell
            antoinetran Antoine Tran
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: