Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpServletRequest.getParameterMap - UnmodifiableMap does not wrap a jetty MultiMap #12578

Closed
mreiterer opened this issue Nov 26, 2024 · 5 comments · Fixed by #12585
Closed
Labels
Bug For general bugs on Jetty side

Comments

@mreiterer
Copy link

Jetty version(s)
Jetty 12

Jetty Environment
ee10

Java version/vendor (use: java -version)

openjdk 21.0.3 2024-04-16 LTS
OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode)

OS type/version
MacOS

Description
Jetty 11 behaviour:

Map<String, String[]> parameterMap = request.getParameterMap();
parameterMap is of type: java.util.Collections$UnmodifiableMap, wraps a org.eclipse.jetty.util.MultiMap

Calling toString (or directly hand the map over to a slf4j / logback) on parameterMap delivers a pretty printed represenation of the multi value map.

Sample output: params: {param1=[abc, def],param2=[xzy]}

Jetty 12 behaviour:

Map<String, String[]> parameterMap = request.getParameterMap();
parameterMap is of type: java.util.Collections$UnmodifiableMap, wraps a java.util.LinkedHashMap

Calling toString on parameterMap delivers eg:

{param1=[Ljava.lang.String;@5738c092, param2=[Ljava.lang.String;@7f038407}

Question
Is this an intentional change ?

@mreiterer mreiterer added the Bug For general bugs on Jetty side label Nov 26, 2024
@joakime
Copy link
Contributor

joakime commented Nov 26, 2024

In Jetty 12, the request.getParameters() implementation returns a org.eclipse.jetty.util.Fields object.

The request.getParameterMap() basically returns the result of Fields.toStringArrayMap() (a java.util.LinkedHashMap), but wrapped via Collections.unmodifiableMap.

There's no MultIMap in use for this process.

@joakime
Copy link
Contributor

joakime commented Nov 26, 2024

We cannot fix the LinkedHashMap.toString() output, for obvious reasons.

@gregw
Copy link
Contributor

gregw commented Nov 26, 2024

We cannot fix the LinkedHashMap.toString() output, for obvious reasons.

But we can override toString when we create the linked hash map in org.eclipse.jetty.util.Fields#toStringArrayMap, which I think will be enough.... let me have a play as I like good toString implementations

gregw added a commit that referenced this issue Nov 26, 2024
Fix #12578 pretty print getParameterMap
Added test for parameters
@gregw
Copy link
Contributor

gregw commented Nov 26, 2024

@mreiterer see #12585

@mreiterer
Copy link
Author

@gregw Thanks !

gregw added a commit that referenced this issue Nov 27, 2024
Fix #12578 pretty print getParameterMap
checkstyle
gregw added a commit that referenced this issue Nov 28, 2024
Fix #12578 pretty print getParameterMap
Added TypeUtil method
@gregw gregw closed this as completed in a8aec30 Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants