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:
@@ -253,6 +253,7 @@ public class ServerPlugin extends Plugin {
|
||||
public File get() {
|
||||
if (!ready) {
|
||||
synchronized (dataDir) {
|
||||
if (!ready) {
|
||||
if (!dataDir.exists() && !dataDir.mkdirs()) {
|
||||
throw new ProvisionException(String.format(
|
||||
"Cannot create %s for plugin %s",
|
||||
@@ -261,6 +262,7 @@ public class ServerPlugin extends Plugin {
|
||||
ready = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataDir;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user