提交 ff89dde4 编写于 作者: M malenkov

8012716: java.beans.EventHandler.create method should check if the given...

8012716: java.beans.EventHandler.create method should check if the given listenerInterface is a public interface
Reviewed-by: art, mchung
上级 eeda6eb4
...@@ -33,6 +33,7 @@ import java.security.AccessController; ...@@ -33,6 +33,7 @@ import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import sun.reflect.misc.MethodUtil; import sun.reflect.misc.MethodUtil;
import sun.reflect.misc.ReflectUtil;
/** /**
* The <code>EventHandler</code> class provides * The <code>EventHandler</code> class provides
...@@ -677,22 +678,38 @@ public class EventHandler implements InvocationHandler { ...@@ -677,22 +678,38 @@ public class EventHandler implements InvocationHandler {
* *
* @see EventHandler * @see EventHandler
*/ */
@SuppressWarnings("unchecked")
public static <T> T create(Class<T> listenerInterface, public static <T> T create(Class<T> listenerInterface,
Object target, String action, Object target, String action,
String eventPropertyName, String eventPropertyName,
String listenerMethodName) String listenerMethodName)
{ {
// Create this first to verify target/action are non-null // Create this first to verify target/action are non-null
EventHandler eventHandler = new EventHandler(target, action, final EventHandler handler = new EventHandler(target, action,
eventPropertyName, eventPropertyName,
listenerMethodName); listenerMethodName);
if (listenerInterface == null) { if (listenerInterface == null) {
throw new NullPointerException( throw new NullPointerException(
"listenerInterface must be non-null"); "listenerInterface must be non-null");
} }
return (T)Proxy.newProxyInstance(target.getClass().getClassLoader(), final ClassLoader loader = getClassLoader(listenerInterface);
new Class<?>[] {listenerInterface}, final Class<?>[] interfaces = {listenerInterface};
eventHandler); return AccessController.doPrivileged(new PrivilegedAction<T>() {
@SuppressWarnings("unchecked")
public T run() {
return (T) Proxy.newProxyInstance(loader, interfaces, handler);
}
});
}
private static ClassLoader getClassLoader(Class<?> type) {
ReflectUtil.checkPackageAccess(type);
ClassLoader loader = type.getClassLoader();
if (loader == null) {
loader = Thread.currentThread().getContextClassLoader(); // avoid use of BCP
if (loader == null) {
loader = ClassLoader.getSystemClassLoader();
}
}
return loader;
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册