Bug 564747

Summary: Empty-valued query parameters in request URLs are returned twice, once with an empty value and once with a null value
Product: [Eclipse Project] Equinox Reporter: John Vasta <john.vasta>
Component: CompendiumAssignee: Thomas Watson <tjwatson>
Status: RESOLVED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: loskutov, tjwatson
Version: 4.14Keywords: regression
Target Milestone: 4.17 M1   
Hardware: All   
OS: All   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=500783
https://git.eclipse.org/r/c/equinox/rt.equinox.bundles/+/165580
https://git.eclipse.org/c/equinox/rt.equinox.bundles.git/commit/?id=b4a5f29b1a77de9e1fd21936ce073af27ccfb157
https://git.eclipse.org/r/c/equinox/rt.equinox.bundles/+/168477
https://git.eclipse.org/c/equinox/rt.equinox.bundles.git/commit/?id=5fefc476e2dcec3fac983ca55c4fe30f06e07477
https://git.eclipse.org/r/c/equinox/rt.equinox.bundles/+/171314
https://git.eclipse.org/c/equinox/rt.equinox.bundles.git/commit/?id=63fdaf56c3dc4445e2ae9af3185f5835928d3cd4
Whiteboard:
Attachments:
Description Flags
servlet illustrating behavior of empty-valued parameters none

Description John Vasta CLA 2020-06-29 13:15:30 EDT
Created attachment 283433 [details]
servlet illustrating behavior of empty-valued parameters

In an application that is deployed in a JEE servlet container using the Equinox bridge servlet, an incoming request URI with an empty-valued query parameter (e.g. "?param=") results in two values returned by HttpServletRequest#getParameterMap, one with the value being an empty string (which is correct), and one with a null value (which is incorrect). According to the JEE servlet specifications, a null value is only returned for parameters that do not exist at all in the request URI query string. If a parameter name is followed by an equals sign but no value, the parameter value is the empty string.

This breaks our applications significantly, because we have services with required parameters where a single parameter instance is required, but the value is allowed to be empty. When our code gets a null value, that means the parameter was not specified by the client, which is an error.

I'm adding a zip of a servlet project illustrating the problem; it can be deployed as an embedded Equinox application. (It is a variant of the example I attached to bug 562843).

It appears this defect was surfaced by the fix for bug 500783. The actual problem is in the DispatchTargets#queryStringToParameterMap method - it is returning null for empty-valued parameters. Then the DispatchTargets#getParameterMap method merges those values with the values from the incoming request's getParameterMap result (which contains the correct empty string value), resulting in two values for the same parameter, one being null.
Comment 1 Eclipse Genie CLA 2020-06-29 14:44:25 EDT
New Gerrit change created: https://git.eclipse.org/r/c/equinox/rt.equinox.bundles/+/165580
Comment 3 Thomas Watson CLA 2020-06-29 15:32:16 EDT
Thanks, I added a testcase and a fix for 4.17 release.
Comment 4 Eclipse Genie CLA 2020-08-31 09:29:25 EDT
New Gerrit change created: https://git.eclipse.org/r/c/equinox/rt.equinox.bundles/+/168477
Comment 6 Eclipse Genie CLA 2020-10-26 13:39:33 EDT
New Gerrit change created: https://git.eclipse.org/r/c/equinox/rt.equinox.bundles/+/171314