Describe the bug
JavaLogFactory.java's readLoggerConfiguration function throws ConcurrentModificationException at this line
if (System.getProperties().keySet().stream().anyMatch(propKey ->
"java.util.logging.config.class".equals(propKey) || "java.util.logging.config.file".equals(propKey)))
in a multi-threaded environment when another thread is concurrently setting system properties while ESAPI is iterating over system properties.
Specify what ESAPI version(s) you are experiencing this bug in
2.5.2.0
To Reproduce
publicclassReproduce {
publicstaticvoidmain(String[] args) {
Threadt = newThread(newRunnable() {
publicvoidrun() {
while (true) {
longtime = System.currentTimeMillis();
// Emulate another thread modifying system propertiesSystem.setProperty(time + "", time + "");
try {
Thread.sleep(500);
} catch (InterruptedExceptione) {
e.printStackTrace();
}
}
}
}); t.start();
EsapiThreadesapiThread = newEsapiThread();
esapiThread.start();
}
privatestaticclassEsapiThreadextendsThread {
publicvoidrun() {
// Emulate the code of JavaLogFactory in ESAPISystem.getProperties().keySet().stream().anyMatch(a -> {
try {
Thread.sleep(2000);
} catch (InterruptedExceptione) {
thrownewRuntimeException(e);
}
return"dummy".equals(a);
});
}
}
}Expected behavior
Proposed change: copy the System.getProperties().keySet() to a new collection and iterating over the new collection instead of the original one to avoid thread safety problem.
Platform environment (please complete the following information)
Describe the bug
JavaLogFactory.java's readLoggerConfiguration function throws ConcurrentModificationException at this line
in a multi-threaded environment when another thread is concurrently setting system properties while ESAPI is iterating over system properties.
Specify what ESAPI version(s) you are experiencing this bug in
2.5.2.0
To Reproduce
Expected behavior
Proposed change: copy the
System.getProperties().keySet()to a new collection and iterating over the new collection instead of the original one to avoid thread safety problem.Platform environment (please complete the following information)