Fix possible data race condition

This issue was found by scan.coverity.com (CID 19961)
which is a static code analysis tool, free for open source
code.

Assuming we have two threads both can pass the !ready
condition before entering the critical section protected with
"synchronized (dataDir)". So theoretically both threads will
arrive at setting ready to true.

Change-Id: I4b833279d755b32e4b1e0817cca5584c21c6346a
This commit is contained in:
Stefan Beller
2015-02-02 14:45:19 -08:00
parent 3695e7ebc9
commit 9fdf1d4738

View File

@@ -253,12 +253,14 @@ public class ServerPlugin extends Plugin {
public File get() {
if (!ready) {
synchronized (dataDir) {
if (!dataDir.exists() && !dataDir.mkdirs()) {
throw new ProvisionException(String.format(
"Cannot create %s for plugin %s",
dataDir.getAbsolutePath(), getName()));
if (!ready) {
if (!dataDir.exists() && !dataDir.mkdirs()) {
throw new ProvisionException(String.format(
"Cannot create %s for plugin %s",
dataDir.getAbsolutePath(), getName()));
}
ready = true;
}
ready = true;
}
}
return dataDir;