[JENKINS-48738] Fix NPE when setting JDK #203
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix null pointer exception when setting JDK
See the original proposed change at a15d15a
Confirmed with interactive testing that the null pointer exception is resolved and that the configuration slicing plugin can change the value of the JDK that is defined on a Freestyle job. I changed between jdk-8 and jdk-20.
The plugin cannot reset the definition of the JDK to the default because that causes a null pointer exception in AbstractProject as reported by the original bug report JENKINS-48738
Avoid the null pointer exception by ignoring the attempt to reset the JDK value to default.
Thanks to @Evildethow and @ahertier for implementation
Testing done
Interactive testing of freestyle project with Jenkins 2.401. I configured two JDK tool values, jdk-8 and jdk-20, then assigned one of the values to the job. The configuration slicing plugin with this change is able to change the configuration from jdk-8 to jdk-20 and from jdk-20 to jdk-8. The attempt to change JDK to an empty string is sliently ignored rather than generating a null pointer exception.
AbstractProject does not seem to have a method that will allow the JDK of a project to be reset to the default value. The user interface is able to make that change, but apparently it makes the change without passing a
null
tosetJDK()
.Submitter checklist