Skip to content

Fix NPE in createValue when content type is null#267

Open
Axonis wants to merge 2 commits into
jenkinsci:masterfrom
Axonis:fix/null-content-type-npe
Open

Fix NPE in createValue when content type is null#267
Axonis wants to merge 2 commits into
jenkinsci:masterfrom
Axonis:fix/null-content-type-npe

Conversation

@Axonis
Copy link
Copy Markdown

@Axonis Axonis commented May 20, 2026

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

  • [ x ] Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • [ x ] Ensure that the pull request title represents the desired changelog entry
  • [ x ] Please describe what you did
  • [ x ] Link to relevant issues in GitHub or Jira
  • [ x ] Link to relevant pull requests, esp. upstream and downstream changes
  • [ x ] Ensure you have provided tests that demonstrate the feature works or the issue is fixed

Axonis added 2 commits May 20, 2026 18:02
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.
@Axonis Axonis requested a review from a team as a code owner May 20, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stashedFile stopped working when triggering another build

1 participant