6636369: sun.awt.datatransfer.DataTransferer contains double-check idiom

Double-check has been removed

Reviewed-by: dav
This commit is contained in:
Oleg Sukhodolsky 2008-03-13 16:47:40 +03:00
parent 43fd376e71
commit 59d9653ecf

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -270,62 +270,58 @@ public abstract class DataTransferer {
* instead, null will be returned. * instead, null will be returned.
*/ */
public static DataTransferer getInstance() { public static DataTransferer getInstance() {
if (transferer == null) { synchronized (DataTransferer.class) {
synchronized (DataTransferer.class) { if (transferer == null) {
if (transferer == null) { final String name = SunToolkit.getDataTransfererClassName();
final String name = SunToolkit. if (name != null) {
getDataTransfererClassName(); PrivilegedAction<DataTransferer> action = new PrivilegedAction<DataTransferer>()
if (name != null) { {
PrivilegedAction action = new PrivilegedAction() { public DataTransferer run() {
public Object run() { Class cls = null;
Class cls = null; Method method = null;
Method method = null; DataTransferer ret = null;
Object ret = null;
try { try {
cls = Class.forName(name); cls = Class.forName(name);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
ClassLoader cl = ClassLoader. ClassLoader cl = ClassLoader.
getSystemClassLoader(); getSystemClassLoader();
if (cl != null) { if (cl != null) {
try {
cls = cl.loadClass(name);
} catch (ClassNotFoundException ee) {
ee.printStackTrace();
throw new AWTError("DataTransferer not found: " + name);
}
}
}
if (cls != null) {
try { try {
method = cls.getDeclaredMethod cls = cl.loadClass(name);
("getInstanceImpl"); } catch (ClassNotFoundException ee) {
method.setAccessible(true); ee.printStackTrace();
} catch (NoSuchMethodException e) { throw new AWTError("DataTransferer not found: " + name);
e.printStackTrace();
throw new AWTError("Cannot instantiate DataTransferer: " + name);
} catch (SecurityException e) {
e.printStackTrace();
throw new AWTError("Access is denied for DataTransferer: " + name);
} }
} }
if (method != null) {
try {
ret = method.invoke(null);
} catch (InvocationTargetException e) {
e.printStackTrace();
throw new AWTError("Cannot instantiate DataTransferer: " + name);
} catch (IllegalAccessException e) {
e.printStackTrace();
throw new AWTError("Cannot access DataTransferer: " + name);
}
}
return ret;
} }
}; if (cls != null) {
transferer = (DataTransferer) try {
AccessController.doPrivileged(action); method = cls.getDeclaredMethod("getInstanceImpl");
} method.setAccessible(true);
} catch (NoSuchMethodException e) {
e.printStackTrace();
throw new AWTError("Cannot instantiate DataTransferer: " + name);
} catch (SecurityException e) {
e.printStackTrace();
throw new AWTError("Access is denied for DataTransferer: " + name);
}
}
if (method != null) {
try {
ret = (DataTransferer) method.invoke(null);
} catch (InvocationTargetException e) {
e.printStackTrace();
throw new AWTError("Cannot instantiate DataTransferer: " + name);
} catch (IllegalAccessException e) {
e.printStackTrace();
throw new AWTError("Cannot access DataTransferer: " + name);
}
}
return ret;
}
};
transferer = AccessController.doPrivileged(action);
} }
} }
} }