summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2014-08-13 09:02:41 +0200
committerNoel Grandin <noel@peralex.com>2014-08-20 10:35:51 +0200
commit252ed1708ad5a007e4c47c243595206650876a2b (patch)
treeb2a7a47f8a39c598c25355640a77022918c2d209
parenta240a78cc771a89febfe181abe78d2cf16e1970f (diff)
double-checked locking is not thread-safe in Java
found by PMD Change-Id: Ibd4a9139c626932bec56c0b1dd32b4d59c8440b1
-rw-r--r--javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java10
-rw-r--r--scripting/java/com/sun/star/script/framework/container/XMLParserFactory.java10
-rw-r--r--scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java12
-rw-r--r--scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java12
-rw-r--r--scripting/java/org/openoffice/idesupport/zip/ParcelZipper.java10
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/utils/ManifestParser.java7
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/utils/ZipMounter.java10
-rw-r--r--scripting/workben/ifc/scripting/ScriptingUtils.java10
-rw-r--r--sw/qa/complex/writer/CheckBookmarks.java4
-rw-r--r--toolkit/qa/complex/toolkit/Assert.java2
-rw-r--r--toolkit/test/accessibility/AccessibleTextHandler.java6
11 files changed, 28 insertions, 65 deletions
diff --git a/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java b/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java
index 2c808e3e9866..ca72af9c81ac 100644
--- a/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java
+++ b/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java
@@ -358,16 +358,10 @@ XMultiPropertySet
}
}
//XPropertySet ----------------------------------------------------
- public com.sun.star.beans.XPropertySetInfo getPropertySetInfo()
+ public synchronized com.sun.star.beans.XPropertySetInfo getPropertySetInfo()
{
if (propertySetInfo == null)
- {
- synchronized (this)
- {
- if (propertySetInfo == null)
- propertySetInfo= new PropertySetInfo();
- }
- }
+ propertySetInfo= new PropertySetInfo();
return propertySetInfo;
}
//XPropertySet ----------------------------------------------------
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;
}
diff --git a/scripting/java/org/openoffice/idesupport/zip/ParcelZipper.java b/scripting/java/org/openoffice/idesupport/zip/ParcelZipper.java
index 45cdb185f313..e1e12fa56d83 100644
--- a/scripting/java/org/openoffice/idesupport/zip/ParcelZipper.java
+++ b/scripting/java/org/openoffice/idesupport/zip/ParcelZipper.java
@@ -39,13 +39,9 @@ public class ParcelZipper
private ParcelZipper() {
}
- public static ParcelZipper getParcelZipper() {
- if (zipper == null) {
- synchronized(ParcelZipper.class) {
- if (zipper == null)
- zipper = new ParcelZipper();
- }
- }
+ public static synchronized ParcelZipper getParcelZipper() {
+ if (zipper == null)
+ zipper = new ParcelZipper();
return zipper;
}
diff --git a/scripting/java/org/openoffice/netbeans/modules/office/utils/ManifestParser.java b/scripting/java/org/openoffice/netbeans/modules/office/utils/ManifestParser.java
index 892313332a14..1859ec60865e 100644
--- a/scripting/java/org/openoffice/netbeans/modules/office/utils/ManifestParser.java
+++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/ManifestParser.java
@@ -41,12 +41,9 @@ public class ManifestParser implements XMLParser {
private ManifestParser() {
}
- public static ManifestParser getManifestParser() {
+ public static synchronized ManifestParser getManifestParser() {
if (parser == null) {
- synchronized(ManifestParser.class) {
- if (parser == null)
- parser = new ManifestParser();
- }
+ parser = new ManifestParser();
}
return parser;
}
diff --git a/scripting/java/org/openoffice/netbeans/modules/office/utils/ZipMounter.java b/scripting/java/org/openoffice/netbeans/modules/office/utils/ZipMounter.java
index 8a1bc1849ac4..7150ef81e541 100644
--- a/scripting/java/org/openoffice/netbeans/modules/office/utils/ZipMounter.java
+++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/ZipMounter.java
@@ -34,13 +34,9 @@ public class ZipMounter
private ZipMounter() {
}
- public static ZipMounter getZipMounter() {
- if (mounter == null) {
- synchronized(ZipMounter.class) {
- if (mounter == null)
- mounter = new ZipMounter();
- }
- }
+ public static synchronized ZipMounter getZipMounter() {
+ if (mounter == null)
+ mounter = new ZipMounter();
return mounter;
}
diff --git a/scripting/workben/ifc/scripting/ScriptingUtils.java b/scripting/workben/ifc/scripting/ScriptingUtils.java
index ce6071c78dd2..eb317036e2ab 100644
--- a/scripting/workben/ifc/scripting/ScriptingUtils.java
+++ b/scripting/workben/ifc/scripting/ScriptingUtils.java
@@ -34,13 +34,9 @@ public class ScriptingUtils {
private ScriptingUtils() {
}
- public static ScriptingUtils getDefault() {
- if (utils == null) {
- synchronized (ScriptingUtils.class) {
- if (utils == null)
- utils = new ScriptingUtils();
- }
- }
+ public static synchronized ScriptingUtils getDefault() {
+ if (utils == null)
+ utils = new ScriptingUtils();
return utils;
}
diff --git a/sw/qa/complex/writer/CheckBookmarks.java b/sw/qa/complex/writer/CheckBookmarks.java
index 348844cf4868..0e72bc851bcc 100644
--- a/sw/qa/complex/writer/CheckBookmarks.java
+++ b/sw/qa/complex/writer/CheckBookmarks.java
@@ -71,9 +71,9 @@ class BookmarkHashes {
XTextContent.class,
xBookmark);
buffer.append(sBookmarkname);
- buffer.append(":");
+ buffer.append(':');
buffer.append(xBookmarkAsContent.getAnchor().getString());
- buffer.append(";");
+ buffer.append(';');
}
java.security.MessageDigest sha1 = java.security.MessageDigest.getInstance("SHA-1");
sha1.reset();
diff --git a/toolkit/qa/complex/toolkit/Assert.java b/toolkit/qa/complex/toolkit/Assert.java
index 0bda0b65c242..eb6ec44dce1e 100644
--- a/toolkit/qa/complex/toolkit/Assert.java
+++ b/toolkit/qa/complex/toolkit/Assert.java
@@ -59,7 +59,7 @@ public class Assert
catch ( NoSuchMethodException e )
{
StringBuilder message = new StringBuilder();
- message.append( "no such method: " ).append( objectClass.getName() ).append( "." ).append( i_methodName ).append( "( " );
+ message.append( "no such method: " ).append( objectClass.getName() ).append( '.' ).append( i_methodName ).append( "( " );
for ( int i=0; i<i_argClasses.length; ++i )
{
message.append( i_argClasses[i].getName() );
diff --git a/toolkit/test/accessibility/AccessibleTextHandler.java b/toolkit/test/accessibility/AccessibleTextHandler.java
index 39ecbad6e4bc..acd2f0208005 100644
--- a/toolkit/test/accessibility/AccessibleTextHandler.java
+++ b/toolkit/test/accessibility/AccessibleTextHandler.java
@@ -249,11 +249,11 @@ class AccessibleTextHandler extends NodeHandler
StringBuffer aChars = new StringBuffer();
try
{
- aChars.append( "[" );
+ aChars.append( '[' );
for( int i = 0; i < nChars; i++)
{
aChars.append( xText.getCharacter(i) );
- aChars.append( "," );
+ aChars.append( ',' );
}
if( nChars > 0)
{
@@ -262,7 +262,7 @@ class AccessibleTextHandler extends NodeHandler
else
aChars.append( "..." );
}
- aChars.append( "]" );
+ aChars.append( ']' );
}
catch( IndexOutOfBoundsException e )
{