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

j:getStatic/invokeStatic does not work on plugin classes

XMLWordPrintable

      If in j:getStatic or j:invokeStatic you specify a className which is in a plugin, then try to render the resulting Jelly view, you get

      java.lang.ClassNotFoundException: some.Class
      	at org.jenkinsci.maven.plugins.hpi.ServletApiOnlyClassLoader.findClass(ServletApiOnlyClassLoader.java:25)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      	at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:363)
      	at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:325)
      	at org.apache.commons.jelly.tags.core.GetStaticTag.doTag(GetStaticTag.java:106)
      

      Indeed GetStaticTag does

      Class type = ClassLoaderUtils.getClassLoader(getClass()).loadClass(className);
      

      which calls

      public static ClassLoader getClassLoader(Class clazz) {
          ClassLoader callersLoader = clazz.getClassLoader();
          if (callersLoader == null) {
              callersLoader = ClassLoader.getSystemClassLoader();
          }
          return callersLoader;
      }
      

      so there is no way this could work.

      Workaround:

      ${app.pluginManager.uberClassLoader.loadClass('some.Class').getField('field').get(null)}
      ${app.pluginManager.uberClassLoader.loadClass('pkg.SomeExtension').getMethod('all', null).invoke(null, null)}
      

            Unassigned Unassigned
            jglick Jesse Glick
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: