Fix issue #761: ThreadSafeDoubleCheckLocking.java: Instantiating by Reflection call will be successful if you do that firstly (#920)
This commit is contained in:
committed by
Ilkka Seppälä
parent
8c865e6b4d
commit
f1410337b5
@ -35,12 +35,16 @@ public final class ThreadSafeDoubleCheckLocking {
|
||||
|
||||
private static volatile ThreadSafeDoubleCheckLocking instance;
|
||||
|
||||
private static boolean flag = true;
|
||||
|
||||
/**
|
||||
* private constructor to prevent client from instantiating.
|
||||
*/
|
||||
private ThreadSafeDoubleCheckLocking() {
|
||||
// to prevent instantiating by Reflection call
|
||||
if (instance != null) {
|
||||
if (flag) {
|
||||
flag = false;
|
||||
} else {
|
||||
throw new IllegalStateException("Already initialized.");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user