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.
Comment From: sbrannen
I guess an empty file input field should just be ignored,
Perhaps instead of ignoring it we should fall back to the default handling and add the parameter's name and value to the request (as if it were not a KeyDataPair).
@rstoyanchev, thoughts?
Comment From: sbrannen
This has been fixed in main (in 959e6d17458dbef0bf3572b8c0fe33d714e7c2f0) and will be available in the upcoming 5.3.7 snapshot builds.
@tloist, it would be great if you could try this out with a snapshot build and let us know if the fix works for your use cases.
Comment From: tloist
Yes, we will try to. It's actual not my nor my projects setup so I am acting more or less as a proxy. I just helped find the root cause and wanted to communicate it back.
I am gently, well, pushing for it, but I am not into their timeline so I can't exactly say when to expect some results. I am however actively advocating my help and understand why it would be great to have actual feedback on the issue. Please don't think I am not interested anymore - it's just a bit more complicated as I'd like it to be but I am on it.
Comment From: sbrannen
Please don't think I am not interested anymore - it's just a bit more complicated as I'd like it to be but I am on it.
Understood!
Please note that I have slightly revised the fix in d79e33b5a0182af51f4c236fa59a99884d5a5f71.