-
Notifications
You must be signed in to change notification settings - Fork 49
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
fix: ConcurrentModificationException on flag config change java 9 #954
Conversation
Signed-off-by: Todd Baert <[email protected]>
Assert.assertEquals(expectedChangedFlags.keySet().stream().collect(Collectors.toList()), | ||
storageStateDTOS.take().getChangedFlagsKeys()); | ||
// flags changed from initial VALID_SIMPLE flag, as a set because we don't care about order | ||
Assert.assertEquals(expectedChangedFlags.keySet().stream().collect(Collectors.toSet()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert would inconsistently fail because of ordering inconsistencies.
@@ -98,9 +99,9 @@ public void changedFlags() throws Exception { | |||
Map<String, FeatureFlag> expectedChangedFlags = | |||
FlagParser.parseString(getFlagsFromResource(VALID_LONG),true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call would intermittently fail in Java 9+ due to concurrent modification exceptions.
private static final ObjectMapper MAPPER = new ObjectMapper(); | ||
private static final Map<String, Pattern> PATTERN_MAP = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field presents a concurrency issue, since multiple threads can possible parse at the same time, and computeIfAbsent
can throw an concurrent-modification-exception in Java 9+
We had a static hashmap that could possibly be modified by multiple threads since
computeIfAbsent
mutates the map.This is specifically more visible in Java 9 due to some new additional checks. This is easily solved by making this static member a local variable.