Skip to content

Commit

Permalink
Fixes #2500
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Mar 18, 2024
1 parent fea1c6c commit 84c59d4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,15 @@ public String getHeader(String s, boolean checkCase) {
public String getParameter(String s) {
String name = isNotNoOps() ? b.request.getParameter(s) : null;
if (name == null) {
if (b.queryStrings.get(s) != null) {
return b.queryStrings.get(s)[0];
String[] values = b.queryStrings.get(s);
if (values != null) {
return values[0];
}
}
return name;
}


@Override
public Map<String, String[]> getParameterMap() {
if (!queryComputed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import static org.mockito.Mockito.mock;
Expand All @@ -40,6 +43,7 @@
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.AssertJUnit.fail;

public class AtmosphereRequestTest {
private AtmosphereFramework framework;
Expand Down Expand Up @@ -351,5 +355,41 @@ public void testWrapMethodWithNullAttributeValue() throws IOException, ServletEx
assertNull(wrappedRequest.getAttribute("org.eclipse.jetty.multipartConfig"), "Attribute value should be null");
}

public class AtmosphereRequestImplTest {

@Test
public void testGetParameterRaceCondition() throws InterruptedException {
final Map<String, String[]> queryStrings = Collections.synchronizedMap(new HashMap<>());
queryStrings.put("testParam", new String[]{"testValue"});

AtmosphereRequestImpl.Builder builder = new AtmosphereRequestImpl.Builder();
builder.queryStrings(queryStrings);

final AtmosphereRequest request = builder.build();

Runnable addAndRemove = () -> {
queryStrings.put("testParam", new String[]{"testValue"});
queryStrings.remove("testParam");
};

Runnable getParameter = () -> {
try {
request.getParameter("testParam");
} catch (NullPointerException e) {
fail("NullPointerException occurred");
}
};

ExecutorService executor = Executors.newFixedThreadPool(2);
for (int i = 0; i < 10000; i++) {
executor.execute(addAndRemove);
executor.execute(getParameter);
}

executor.shutdown();
executor.awaitTermination(1, TimeUnit.MINUTES);
}
}


}

0 comments on commit 84c59d4

Please sign in to comment.