• Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • pipeline-model-api:2.2247.va_423189a_7dff
      pipeline-model-definition:2.2247.va_423189a_7dff
      pipeline-model-extensions:2.2247.va_423189a_7dff
      pipeline-stage-tags-metadata:2.2247.va_423189a_7dff
      workflow-cps:4046.v90b_1b_9edec67

      This is very similar to https://issues.jenkins.io/browse/JENKINS-75447; it requires the same fix but is not the full solution.

       

      In recent versions of this plugin, there is at least one option (overrideIndexTriggers) that triggers an exception when selected:

      2025-03-21 22:13:24.517+0000 [id=121] WARNING h.ExpressionFactory2$JexlExpression#evaluate: Caught exception evaluating: descriptor.isOwnerMultibranch(it) in /$stapler/bound/ce48bba7-6b46-4b5a-a16d-87c6dd18dfdf/render. Reason: java.lang.NullPointerException: Cannot invoke "hudson.model.Item.getParent()" because "item" is null
      java.lang.NullPointerException: Cannot invoke "hudson.model.Item.getParent()" because "item" is null
      at PluginClassLoader for branch-api//jenkins.branch.OverrideIndexTriggersJobProperty$DescriptorImpl.isOwnerMultibranch(OverrideIndexTriggersJobProperty.java:67)
      <snip>
      

      This results in the widget itself (with the help and title), but not the actual configuration options (checkboxes). Additionally, an attempt to generate the snippet produces no output and results in a separate exception:

      2025-03-21 22:16:35.120+0000 [id=113] WARNING o.e.j.e.n.ContextHandler$APIContext#log: Error while serving [http://localhost:8080/directive-generator/generateDirective]
      java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "o" is null
      at PluginClassLoader for structs//org.jenkinsci.plugins.structs.describable.DescribableModel.uninstantiate2_(DescribableModel.java:771)
      at PluginClassLoader for structs//org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable.from(UninstantiatedDescribable.java:213)
      at PluginClassLoader for pipeline-model-definition//org.jenkinsci.plugins.pipeline.modeldefinition.generator.OptionsDirective$DescriptorImpl.toGroovy(OptionsDirective.java:144)
      at PluginClassLoader for pipeline-model-definition//org.jenkinsci.plugins.pipeline.modeldefinition.generator.OptionsDirective$DescriptorImpl.toGroovy(OptionsDirective.java:70)
      at PluginClassLoader for pipeline-model-definition//org.jenkinsci.plugins.pipeline.modeldefinition.generator.DirectiveDescriptor.toIndentedGroovy(DirectiveDescriptor.java:63)
      at PluginClassLoader for pipeline-model-definition//org.jenkinsci.plugins.pipeline.modeldefinition.generator.DirectiveGenerator.doGenerateDirective(DirectiveGenerator.java:94)
      at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(Unknown Source)
      at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:484)
      <snip>
      

      To reproduce:

      FROM jenkins/jenkins:2.487 AS base
      RUN echo 2.0 > /usr/share/jenkins/ref/jenkins.install.UpgradeWizard.state
      
      FROM base
      RUN jenkins-plugin-cli --latest=false --verbose -p \
      pipeline-model-api:2.2247.va_423189a_7dff \
      pipeline-model-definition:2.2247.va_423189a_7dff \
      pipeline-model-extensions:2.2247.va_423189a_7dff \
      pipeline-stage-tags-metadata:2.2247.va_423189a_7dff \
      workflow-cps:4046.v90b_1b_9edec67
      

      Create a regular pipeline job (does not need any configuration or definition) and click the "Pipeline Syntax" link. Go to the declarative generator, select "options" from the dropdown, and then "Add" an "overrideIndexTriggers" option. That generates the first NPE above, and clicking "Generate Declarative Directive" results in the second.

      The first exception (during page rendering) goes away after applying the fix from https://issues.jenkins.io/browse/JENKINS-75447 but the second (actual snippet generation) remains.  While they are technically separate issues, it makes sense to treat them as one issue, but separately from the other ticket due to the wider scope.  I'll submit a proposed solution shortly.

      Note: the first issue is known to be related to the EE9 migration, but the second issue predates that initiative.  Most of the code involved has not changed for a long time; I have not tried tried identifying why/when it actually broke.

          [JENKINS-75468] Generator fails to emit some options due to NPE

          Roberto Villarreal added a comment - I've created https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/778 for this.

          Basil Crow added a comment -

          I am not sure offhand whether it is expected to get a null instance here. I can spend some more time looking into this next week. Before I dig too deeply into this, I was wondering if mawinter69 might be interested in taking a look to see if any recent(ish) UI changes come to mind. If not, I can spend more time on this next week.

          Basil Crow added a comment - I am not sure offhand whether it is expected to get a null instance here. I can spend some more time looking into this next week. Before I dig too deeply into this, I was wondering if mawinter69 might be interested in taking a look to see if any recent(ish) UI changes come to mind. If not, I can spend more time on this next week.

          Yeah, the fact that the OptionsDirective constructor allowed null options, that it would fail to generate if a null option was present, and that the OverrideIndexTriggersJobProperty will return null when not selected have all been in place for many years.  My initial guess (mentioned on the PR) was also that a UI change (perhaps in combination with some of the previous properties/traits refactors) resulted in this theoretical bug becoming a real on.

          Roberto Villarreal added a comment - Yeah, the fact that the OptionsDirective constructor allowed null options, that it would fail to generate if a null option was present, and that the OverrideIndexTriggersJobProperty will return null when not selected have all been in place for many years.  My initial guess (mentioned on the PR) was also that a UI change (perhaps in combination with some of the previous properties/traits refactors) resulted in this theoretical bug becoming a real on.

          Markus Winter added a comment -

          Not sure if this is caused by any UI changes. I can see that error also with Jenkins 2.462.3

          The problem can also be seen with other options. A general pattern seems to be that when an option has a single checkbox and when this is not checked then generating the snippet fails

          An incomplete list where this applies.

          "Preserve stashed from completed builds" 
          "AuthorizationMatrixProperty"
          "Discard old builds"
          "Do not allow concurrent builds"
          "durabilityHint: Pipeline speed/durability override"

           

          Another more complex example

          Select "rateLimitBuilds: Throttle builds" -> click the checkbox, then enter 0 for number of builds (of course this is not valid but triggers the problem as well), values > 0 lead to proper generation of the snippet

           

          Others are completely broken

          e.g. install https://plugins.jenkins.io/sidebar-link/ plugin, then select "Sidebar Link", no way to get this generated, tick the checkbox, add a link, fill all fields, it still fails.

           

          Where it works:

          "SkipDefaultCheckout: Skip the default automatic checkout whenever entering a new agent", whether the checkbox is ticked or not generation works

           

          Markus Winter added a comment - Not sure if this is caused by any UI changes. I can see that error also with Jenkins 2.462.3 The problem can also be seen with other options. A general pattern seems to be that when an option has a single checkbox and when this is not checked then generating the snippet fails An incomplete list where this applies. "Preserve stashed from completed builds"  "AuthorizationMatrixProperty" "Discard old builds" "Do not allow concurrent builds" "durabilityHint: Pipeline speed/durability override"   Another more complex example Select "rateLimitBuilds: Throttle builds" -> click the checkbox, then enter 0 for number of builds (of course this is not valid but triggers the problem as well), values > 0 lead to proper generation of the snippet   Others are completely broken e.g. install https://plugins.jenkins.io/sidebar-link/ plugin, then select "Sidebar Link", no way to get this generated, tick the checkbox, add a link, fill all fields, it still fails.   Where it works: "SkipDefaultCheckout: Skip the default automatic checkout whenever entering a new agent", whether the checkbox is ticked or not generation works  

          Roberto Villarreal added a comment -

          After further discussion/review, the original PR to address the issue in this plugin was closed in favor of a fix in stapler: https://github.com/jenkinsci/stapler/pull/660

           

          With one exception, all the options listed in the previous comment work as expected, devoid of errors, using the proposed stapler fix.  The one exception is the sidebar-link.  A valid-but-empty snippet is generated in all cases (options {}{}), but there are also no visible errors or stacktrace.  As the comment applied, that plugin has some bug unrelated to these null values.

          Roberto Villarreal added a comment - After further discussion/review, the original PR to address the issue in this plugin was closed in favor of a fix in stapler: https://github.com/jenkinsci/stapler/pull/660   With one exception, all the options listed in the previous comment work as expected, devoid of errors, using the proposed stapler fix.  The one exception is the sidebar-link.  A valid-but-empty snippet is generated in all cases ( options {}{ }), but there are also no visible errors or stacktrace.  As the comment applied, that plugin has some bug unrelated to these null values.

            rrjjvv Roberto Villarreal
            rrjjvv Roberto Villarreal
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: