Skip to content

Commit

Permalink
Fixes #2501
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Mar 18, 2024
1 parent c9f992c commit fea1c6c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}


}

0 comments on commit fea1c6c

Please sign in to comment.