double-checked locking is not thread-safe in Java
found by PMD Change-Id: Ibd4a9139c626932bec56c0b1dd32b4d59c8440b1
This commit is contained in:
@@ -36,13 +36,9 @@ public class XMLParserFactory {
|
||||
|
||||
private XMLParserFactory() {}
|
||||
|
||||
public static XMLParser getParser() {
|
||||
if (parser == null) {
|
||||
synchronized (XMLParserFactory.class) {
|
||||
if (parser == null)
|
||||
parser = new DefaultParser();
|
||||
}
|
||||
}
|
||||
public static synchronized XMLParser getParser() {
|
||||
if (parser == null)
|
||||
parser = new DefaultParser();
|
||||
return parser;
|
||||
}
|
||||
|
||||
|
@@ -94,18 +94,12 @@ public class ScriptEditorForBeanShell
|
||||
/**
|
||||
* Returns the global ScriptEditorForBeanShell instance.
|
||||
*/
|
||||
public static ScriptEditorForBeanShell getEditor()
|
||||
public static synchronized ScriptEditorForBeanShell getEditor()
|
||||
{
|
||||
if (theScriptEditorForBeanShell == null)
|
||||
{
|
||||
synchronized(ScriptEditorForBeanShell.class)
|
||||
{
|
||||
if (theScriptEditorForBeanShell == null)
|
||||
{
|
||||
theScriptEditorForBeanShell =
|
||||
new ScriptEditorForBeanShell();
|
||||
}
|
||||
}
|
||||
theScriptEditorForBeanShell =
|
||||
new ScriptEditorForBeanShell();
|
||||
}
|
||||
return theScriptEditorForBeanShell;
|
||||
}
|
||||
|
@@ -82,18 +82,12 @@ public class ScriptEditorForJavaScript implements ScriptEditor
|
||||
/**
|
||||
* Returns the global ScriptEditorForJavaScript instance.
|
||||
*/
|
||||
public static ScriptEditorForJavaScript getEditor()
|
||||
public static synchronized ScriptEditorForJavaScript getEditor()
|
||||
{
|
||||
if (theScriptEditorForJavaScript == null)
|
||||
{
|
||||
synchronized(ScriptEditorForJavaScript.class)
|
||||
{
|
||||
if (theScriptEditorForJavaScript == null)
|
||||
{
|
||||
theScriptEditorForJavaScript =
|
||||
new ScriptEditorForJavaScript();
|
||||
}
|
||||
}
|
||||
theScriptEditorForJavaScript =
|
||||
new ScriptEditorForJavaScript();
|
||||
}
|
||||
return theScriptEditorForJavaScript;
|
||||
}
|
||||
|
Reference in New Issue
Block a user