From 252ed1708ad5a007e4c47c243595206650876a2b Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 13 Aug 2014 09:02:41 +0200 Subject: double-checked locking is not thread-safe in Java found by PMD Change-Id: Ibd4a9139c626932bec56c0b1dd32b4d59c8440b1 --- .../star/script/framework/container/XMLParserFactory.java | 10 +++------- .../provider/beanshell/ScriptEditorForBeanShell.java | 12 +++--------- .../provider/javascript/ScriptEditorForJavaScript.java | 12 +++--------- 3 files changed, 9 insertions(+), 25 deletions(-) (limited to 'scripting/java/com/sun/star/script/framework') diff --git a/scripting/java/com/sun/star/script/framework/container/XMLParserFactory.java b/scripting/java/com/sun/star/script/framework/container/XMLParserFactory.java index 3a5989febcc3..bb3bd6f47c34 100644 --- a/scripting/java/com/sun/star/script/framework/container/XMLParserFactory.java +++ b/scripting/java/com/sun/star/script/framework/container/XMLParserFactory.java @@ -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; } diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java index fb88968159a8..34061c473847 100644 --- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java +++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java @@ -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; } diff --git a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java index e7ac14c1b5e8..4755a54c9af9 100644 --- a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java +++ b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java @@ -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; } -- cgit