[JIRA] (JENKINS-60721) Improper use of choice parameter throws NPE

8 views
Skip to first unread message

raihaan.shouhell@autodesk.com (JIRA)

unread,
Jan 10, 2020, 2:59:02 AM1/10/20
to jenkinsc...@googlegroups.com
Raihaan Shouhell created an issue
 
Jenkins / Bug JENKINS-60721
Improper use of choice parameter throws NPE
Issue Type: Bug Bug
Assignee: Unassigned
Components: core, github-branch-source-plugin, workflow-cps-plugin
Created: 2020-01-10 07:58
Priority: Major Major
Reporter: Raihaan Shouhell

On jenkins with pipeline you can specify a jenkinsfile such as

properties([    parameters([        choice(description: "lol")    ])])

 

This jenkinsfile will run but now when you click the build with parameters button and attempt to build you will be greeted with

java.lang.NullPointerException
	at hudson.model.ParametersDefinitionProperty.getParameterDefinition(ParametersDefinitionProperty.java:205)
	at hudson.model.ParametersDefinitionProperty._doBuild(ParametersDefinitionProperty.java:150)
	at jenkins.model.ParameterizedJobMixIn.doBuild(ParameterizedJobMixIn.java:212)
	at jenkins.model.ParameterizedJobMixIn$ParameterizedJob.doBuild(ParameterizedJobMixIn.java:408)
	at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
	at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:396)
	at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:408)
	at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:212)
	at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:145)
	at org.kohsuke.stapler.MetaClass$11.doDispatch(MetaClass.java:535)
	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:747)

Furthermore the github branch source plugin when scanning repositories will throw

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.rangeCheck(ArrayList.java:657)
	at java.util.ArrayList.get(ArrayList.java:433)
	at hudson.model.ChoiceParameterDefinition.getDefaultParameterValue(ChoiceParameterDefinition.java:133)
	at hudson.model.ChoiceParameterDefinition.getDefaultParameterValue(ChoiceParameterDefinition.java:25)
	at jenkins.model.ParameterizedJobMixIn.getDefaultParametersValues(ParameterizedJobMixIn.java:172)
	at jenkins.model.ParameterizedJobMixIn.scheduleBuild2(ParameterizedJobMixIn.java:154)
	at jenkins.model.ParameterizedJobMixIn.scheduleBuild2(ParameterizedJobMixIn.java:145)
	at jenkins.branch.MultiBranchProject.scheduleBuild(MultiBranchProject.java:691)
	at jenkins.branch.MultiBranchProject.access$1200(MultiBranchProject.java:125)
	at jenkins.branch.MultiBranchProject$SCMHeadObserverImpl.doAutomaticBuilds(MultiBranchProject.java:2213)
	at jenkins.branch.MultiBranchProject$SCMHeadObserverImpl.observeExisting(MultiBranchProject.java:2038)
	at jenkins.branch.MultiBranchProject$SCMHeadObserverImpl.observe(MultiBranchProject.java:1998)
	at jenkins.scm.api.trait.SCMSourceRequest.process(SCMSourceRequest.java:357)
	at jenkins.scm.api.trait.SCMSourceRequest.process(SCMSourceRequest.java:249)
	at org.jenkinsci.plugins.github_branch_source.GitHubSCMSource.retrieve(GitHubSCMSource.java:919)

This all seems to stem from the fact that choices is allowed to be an empty list with a null name but multiple parts assume that it has at least one item and a valid name.

See:
https://github.com/jenkinsci/jenkins/blob/ad1ca7101b9b180dc677eef914b1cbd8208d00c8/core/src/main/java/hudson/model/ParametersDefinitionProperty.java#L205
https://github.com/jenkinsci/jenkins/blob/ad1ca7101b9b180dc677eef914b1cbd8208d00c8/core/src/main/java/hudson/model/ChoiceParameterDefinition.java#L133

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

raihaan.shouhell@autodesk.com (JIRA)

unread,
Jan 10, 2020, 3:04:02 AM1/10/20
to jenkinsc...@googlegroups.com
Raihaan Shouhell updated an issue
Change By: Raihaan Shouhell
On jenkins with pipeline you can specify a jenkinsfile such as
{code:java}

properties([    parameters([        choice(description: "lol")    ])])
{code}

 

This jenkinsfile will run but now when you click the build with parameters button and attempt to build you will be greeted with
{code:java}

java.lang.NullPointerException
at hudson.model.ParametersDefinitionProperty.getParameterDefinition(ParametersDefinitionProperty.java:205)
at hudson.model.ParametersDefinitionProperty._doBuild(ParametersDefinitionProperty.java:150)
at jenkins.model.ParameterizedJobMixIn.doBuild(ParameterizedJobMixIn.java:212)
at jenkins.model.ParameterizedJobMixIn$ParameterizedJob.doBuild(ParameterizedJobMixIn.java:408)
at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:396)
at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:408)
at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:212)
at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:145)
at org.kohsuke.stapler.MetaClass$11.doDispatch(MetaClass.java:535)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:747)
{code}
This behaviour seems to affect all parameters


Furthermore the github branch source plugin when scanning repositories will throw
{code:java}

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:657)
at java.util.ArrayList.get(ArrayList.java:433)
at hudson.model.ChoiceParameterDefinition.getDefaultParameterValue(ChoiceParameterDefinition.java:133)
at hudson.model.ChoiceParameterDefinition.getDefaultParameterValue(ChoiceParameterDefinition.java:25)
at jenkins.model.ParameterizedJobMixIn.getDefaultParametersValues(ParameterizedJobMixIn.java:172)
at jenkins.model.ParameterizedJobMixIn.scheduleBuild2(ParameterizedJobMixIn.java:154)
at jenkins.model.ParameterizedJobMixIn.scheduleBuild2(ParameterizedJobMixIn.java:145)
at jenkins.branch.MultiBranchProject.scheduleBuild(MultiBranchProject.java:691)
at jenkins.branch.MultiBranchProject.access$1200(MultiBranchProject.java:125)
at jenkins.branch.MultiBranchProject$SCMHeadObserverImpl.doAutomaticBuilds(MultiBranchProject.java:2213)
at jenkins.branch.MultiBranchProject$SCMHeadObserverImpl.observeExisting(MultiBranchProject.java:2038)
at jenkins.branch.MultiBranchProject$SCMHeadObserverImpl.observe(MultiBranchProject.java:1998)
at jenkins.scm.api.trait.SCMSourceRequest.process(SCMSourceRequest.java:357)
at jenkins.scm.api.trait.SCMSourceRequest.process(SCMSourceRequest.java:249)
at org.jenkinsci.plugins.github_branch_source.GitHubSCMSource.retrieve(GitHubSCMSource.java:919)
{code}

o.v.nenashev@gmail.com (JIRA)

unread,
Jan 17, 2020, 4:43:02 PM1/17/20
to jenkinsc...@googlegroups.com
Oleg Nenashev commented on Bug JENKINS-60721
 
Re: Improper use of choice parameter throws NPE

This part of the Jenkins API has not been annotated yet, but from what I see the code does not expect null parameter names. My suggestion would be to...

  • Annotate the Core API to be explicit about the value expectation.
  • Maybe: Add readResolve() method to replace nulls with something like "UNDEFINED"
  • Fix the bug in the Choice plugin

raihaan.shouhell@autodesk.com (JIRA)

unread,
Feb 9, 2020, 9:45:03 PM2/9/20
to jenkinsc...@googlegroups.com
Raihaan Shouhell resolved as Fixed
 

Not sure how to link the PR's to jira so pasting it here for reference.

Change By: Raihaan Shouhell
Status: Open Resolved
Resolution: Fixed
Released As: https://jenkins.io/changelog/#v2.220
Reply all
Reply to author
Forward
0 new messages