Skip to content

Support empty file uploads with HtmlUnit and MockMvc #26799

@tloist

Description

@tloist

When one uses HtmlUnit as a Web Client for tests, the HtmlUnitRequestBuilder can't cope with empty file input fields. It just tries to access the field instance and throws a NullPointerException.

HtmlUnit produces an KeyValuePair with a null file (so the file variable is explicitly set to null). However the current implementation in Spring doesn't cope well with that field being null, which results in a NullPointerException being thrown.

I guess an empty file input field should just be ignored, so maybe the best way to deal with it would be something along the lines of:

if (pair.getFile() == null) continue;

because I don't think we should drop to the default handling of request.addParameter(param.getName(), param.getValue()); a few lines later.

For reference, I think the problem was introduced in this pull request (1 year)
where as HtmlUnit has this behavior probably longer (the last change on the line was 4 years before). Which is why I think it makes probably more sense to fix it here.

Metadata

Metadata

Assignees

Labels

in: testIssues in the test moduletype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions