diff --git a/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereRequestImpl.java b/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereRequestImpl.java index 91feec5f9e..9e92c5229e 100755 --- a/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereRequestImpl.java +++ b/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereRequestImpl.java @@ -1417,7 +1417,12 @@ public static AtmosphereRequest wrap(HttpServletRequest request) { String s; while (e.hasMoreElements()) { s = e.nextElement(); - b.localAttributes.put(s, attributeWithoutException(request, s)); + Object value = attributeWithoutException(request, s); + if (value != null) { // Check for null values + b.localAttributes.put(s, value); + } else { + logger.warn("Attribute {} is null", s); + } } return b.request(request).build(); } diff --git a/modules/cpr/src/test/java/org/atmosphere/cpr/AtmosphereRequestTest.java b/modules/cpr/src/test/java/org/atmosphere/cpr/AtmosphereRequestTest.java index 7933265aab..841368c4d3 100644 --- a/modules/cpr/src/test/java/org/atmosphere/cpr/AtmosphereRequestTest.java +++ b/modules/cpr/src/test/java/org/atmosphere/cpr/AtmosphereRequestTest.java @@ -24,13 +24,17 @@ import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; @@ -335,4 +339,17 @@ public void testForceContentType() throws Exception { assertNull(request.getContentType()); } + @Test + public void testWrapMethodWithNullAttributeValue() throws IOException, ServletException { + HttpServletRequest mockRequest = mock(HttpServletRequest.class); + when(mockRequest.getAttributeNames()).thenReturn(Collections.enumeration(Arrays.asList("org.eclipse.jetty.multipartConfig"))); + when(mockRequest.getAttribute("org.eclipse.jetty.multipartConfig")).thenReturn(null); + + AtmosphereRequest wrappedRequest = AtmosphereRequestImpl.wrap(mockRequest); + + assertNotNull(wrappedRequest, "Wrapped request should not be null"); + assertNull(wrappedRequest.getAttribute("org.eclipse.jetty.multipartConfig"), "Attribute value should be null"); + } + + }