I was going through java.security.AccessControlContext, and encountered below piece of code:
private static boolean debugInit = false;
private static Debug debug = null;
static Debug getDebug()
{
if (debugInit)
return debug;
else {
if (Policy.isSet()) {
debug = Debug.getInstance("access");
debugInit = true;
}
return debug;
}
}
Question: why do we need an additional variable debugInit
, when we can simple check for if (debug == null)
and getInstance()
like below:
static Debug getDebug()
{
if (debug == null && Policy.isSet()) {
debug = Debug.getInstance("access");
}
return debug;
}
Am I missing something or is there any specific reason to use additional variable debugInit
(which is not referenced anywhere else) ?