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,17 +270,16 @@ 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. final String name = SunToolkit.getDataTransfererClassName();
getDataTransfererClassName();
if (name != null) { if (name != null) {
PrivilegedAction action = new PrivilegedAction() { PrivilegedAction<DataTransferer> action = new PrivilegedAction<DataTransferer>()
public Object run() { {
public DataTransferer run() {
Class cls = null; Class cls = null;
Method method = null; Method method = null;
Object ret = null; DataTransferer ret = null;
try { try {
cls = Class.forName(name); cls = Class.forName(name);
@ -298,8 +297,7 @@ public abstract class DataTransferer {
} }
if (cls != null) { if (cls != null) {
try { try {
method = cls.getDeclaredMethod method = cls.getDeclaredMethod("getInstanceImpl");
("getInstanceImpl");
method.setAccessible(true); method.setAccessible(true);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
e.printStackTrace(); e.printStackTrace();
@ -311,7 +309,7 @@ public abstract class DataTransferer {
} }
if (method != null) { if (method != null) {
try { try {
ret = method.invoke(null); ret = (DataTransferer) method.invoke(null);
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
throw new AWTError("Cannot instantiate DataTransferer: " + name); throw new AWTError("Cannot instantiate DataTransferer: " + name);
@ -323,9 +321,7 @@ public abstract class DataTransferer {
return ret; return ret;
} }
}; };
transferer = (DataTransferer) transferer = AccessController.doPrivileged(action);
AccessController.doPrivileged(action);
}
} }
} }
} }