Fix NPE in createValue when content type is null#267
Open
Axonis wants to merge 2 commits into
Open
Conversation
When build-with-parameters plugin calls createValue() during a GET request (to render the parameter form), the request has no content type. This causes req.getFileItem2() to pass null into Pattern.matcher() inside commons-fileupload2's isMultipartRelated(), triggering a NullPointerException. The existing catch block only handles ServletException wrapping FileUploadContentTypeException, so the NPE escapes. Return null early when the content type is null, matching the existing behavior for non-multipart requests.
Sends a GET request to buildWithParameters, which has no content type header. Before the fix in the previous commit, this would trigger an NPE in commons-fileupload2 when Pattern.matcher() receives null.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When build-with-parameters plugin calls createValue() during a GET request (to render the parameter form), the request has no content type. This causes req.getFileItem2() to pass null into Pattern.matcher() inside commons-fileupload2's isMultipartRelated(), triggering a NullPointerException.
The existing catch block only handles ServletException wrapping FileUploadContentTypeException, so the NPE escapes.
Return null early when the content type is null, matching the existing behavior for non-multipart requests.
Fixes #250
Testing done
Automated: Added restGetRequestNullContentType test that sends a GET request (null content type)
to /buildWithParameters for a job with a file parameter and verifies no NPE is thrown.
Manual: Built the patched plugin, injected it into a local Jenkins instance (via volumenmount over the installed .jpi), and verified that a job with a stashedFile parameter renders the /parambuild/ page without crashing. Tested with the build-with-parameters plugin installed, which calls createValue() during GET rendering. Before the fix, this threw NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "this.text" is null from commons-fileupload2. After the fix, the page renders correctly with prefilled URL parameters.
Submitter checklist