atmosphere icon indicating copy to clipboard operation
atmosphere copied to clipboard

NPE in AtmosphereRequestImpl.wrap

Open mcollovati opened this issue 4 months ago • 0 comments

Describe the bug

In AtmosphereRequestImpl.wrap the request attributes are copied into LocalAttributes instance of request builder one by one. LocalAttributes internally stores attributes in a ConcurrentHashMap, that does not accept null keys or value.

On Jetty 12 a request may contain a null value for an attribute named org.eclipse.jetty.multipartConfig. In this situation the wrap call fails with the following error:

Caused by: java.lang.NullPointerException: null
	at java.base/java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011) ~[na:na]
	at java.base/java.util.concurrent.ConcurrentHashMap.put(ConcurrentHashMap.java:1006) ~[na:na]
	at org.atmosphere.cpr.AtmosphereRequest$LocalAttributes.put(AtmosphereRequest.java:589) ~[atmosphere-runtime-3.0.3.slf4jvaadin2.jar:3.0.3.slf4jvaadin2]
	at org.atmosphere.cpr.AtmosphereRequestImpl.wrap(AtmosphereRequestImpl.java:1450) ~[atmosphere-runtime-3.0.3.slf4jvaadin2.jar:3.0.3.slf4jvaadin2]
	at com.vaadin.flow.server.communication.PushRequestHandler.handleRequest(PushRequestHandler.java:292) ~[flow-server-24.3.5.jar:24.3.5]
	at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1574) ~[flow-server-24.3.5.jar:24.3.5]
	... 55 common frames omitted

Additional note: the wrap method currently calls attributeWithoutException to prevent a potential NPE when getting the attribute from the request (https://github.com/Atmosphere/atmosphere/issues/1732).

Atmosphere Info

  • version: 3.0.3.slf4jvaadin2

Expected behavior

wrap does not fail if there are request attribute keys associated with null values. It could probably ignore the attribute.

Systems (please complete the following information):

  • OS: Linux
  • Java version and distribution: Temurin-17.0.7+7
  • Serveur name and version Jetty 12.0.5

Additional context

Original issue on Vaadin Flow: https://github.com/vaadin/flow/issues/18345

mcollovati avatar Feb 13 '24 17:02 mcollovati