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

MetaClass of Action missing after Jenkins restart

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • groovy-plugin
    • None
    • Jenkins 2.332.3, 2.346.1
      workflow-cps 2692.v76b_089ccd026, 2725.v7b_c717eb_12ce at least
    • workflow-cps-plugin 2801.vf82a_b_b_e3e8a_5

      Since upgrading from Jenkins 2.264.3 to 2.332.3 or 2.346.1 we experience strange problems, that appear to result from a change in groovy.

      Consider the following groovy script, to run in a script console:

      def build = Jenkins.get().getItemByFullName("someJob").getBuildByNumber(someBuild)
      
      println "Build: $build"
      
      def action = org.jenkinsci.plugins.workflow.cps.EnvActionImpl.forRun(build)
      if (action != null) {
          println "Action: " + action
          println "MetaClass: " + action.getMetaClass()
      } else {
         println "no action" 
      }
      

      Replace someJob with a path to a job on your Jenkins instance and someBuild with an existing build number of that job.

      When you run that script, you should get some output showing the build, the action and the action's metaclass. However, after restarting Jenkins, e.g. via /safeRestart and running this script again, you will get a NullPointerException like this when any method is invoked on the action object:

      java.lang.NullPointerException
      	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:41)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
      	at Script1.run(Script1.groovy:8)
      	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:574)
      	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:612)
      	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:583)
      	at hudson.util.RemotingDiagnostics$Script.call(RemotingDiagnostics.java:150)
      	at hudson.util.RemotingDiagnostics$Script.call(RemotingDiagnostics.java:119)
      	at hudson.remoting.LocalChannel.call(LocalChannel.java:47)
      	at hudson.util.RemotingDiagnostics.executeGroovy(RemotingDiagnostics.java:116)
      	at jenkins.model.Jenkins._doScript(Jenkins.java:4726)
      	at jenkins.model.Jenkins.doScript(Jenkins.java:4697)
      	at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:710)
      	at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:397)
      	at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:409)
      	at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:207)
      	at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:140)
      	at org.kohsuke.stapler.MetaClass$11.doDispatch(MetaClass.java:558)
      	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:59)
      	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:766)
      	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:898)
      	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:694)
      	at org.kohsuke.stapler.Stapler.service(Stapler.java:240)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
      	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799)
      	at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1631)
      	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:157)
      	at org.jenkinsci.plugins.ssegateway.Endpoint$SSEListenChannelFilter.doFilter(Endpoint.java:248)
      	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:154)
      	at hudson.plugins.locale.LocaleFilter.doFilter(LocaleFilter.java:42)
      	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:154)
      	at jenkins.telemetry.impl.UserLanguages$AcceptLanguageFilter.doFilter(UserLanguages.java:129)
      	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:154)
      	at jenkins.security.ResourceDomainFilter.doFilter(ResourceDomainFilter.java:81)
      	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:154)
      	at io.jenkins.blueocean.ResourceCacheControl.doFilter(ResourceCacheControl.java:134)
      	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:154)
      ...
      

      It looks like the action object lacks its metaClass and thus fails with the NPE.

      The job's build.xml looks fine, it contains that section from the EnvActionImpl instance. It seems like loading/instantiating that instance on restart does not work properly, though, so the superclass GoovyObjectSupport's metaClass field is null.

      Previously, GroovyObjectSupport recalculated the metaClass on demand, but it doesn't anymore, see https://github.com/apache/groovy/commit/b82049aa20c4d0a8f2d3f0ffd7dc8166b9c6b221

      I don't know why the initial metaClass calculation fails (maybe the EnvActionImpl class is not available yet?) or how to proceed from here.

            vjuranek vjuranek
            capf Carsten Pfeiffer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: