# HG changeset patch
# User alexsch
# Date 1396346167 -14400
# Node ID 204ae465851d3e91af6227e8a982caf79a8370c3
# Parent f0bbc76584d7f5c425d1c2f5d2cd186d37838444
8030052: Remove reflection from JOptionPane
Reviewed-by: serb, pchelko
diff -r f0bbc76584d7 -r 204ae465851d jdk/src/share/classes/java/awt/Container.java
--- a/jdk/src/share/classes/java/awt/Container.java Tue Apr 01 01:59:59 2014 +0400
+++ b/jdk/src/share/classes/java/awt/Container.java Tue Apr 01 13:56:07 2014 +0400
@@ -263,6 +263,16 @@
boolean ignoreEnabled) {
return cont.findComponentAt(x, y, ignoreEnabled);
}
+
+ @Override
+ public void startLWModal(Container cont) {
+ cont.startLWModal();
+ }
+
+ @Override
+ public void stopLWModal(Container cont) {
+ cont.stopLWModal();
+ }
});
}
diff -r f0bbc76584d7 -r 204ae465851d jdk/src/share/classes/javax/swing/JOptionPane.java
--- a/jdk/src/share/classes/javax/swing/JOptionPane.java Tue Apr 01 01:59:59 2014 +0400
+++ b/jdk/src/share/classes/javax/swing/JOptionPane.java Tue Apr 01 13:56:07 2014 +0400
@@ -56,6 +56,7 @@
import javax.swing.event.InternalFrameAdapter;
import javax.accessibility.*;
import static javax.swing.ClientPropertyKey.PopupFactory_FORCE_HEAVYWEIGHT_POPUP;
+import sun.awt.AWTAccessor;
/**
* JOptionPane
makes it easy to pop up a standard dialog box that
@@ -1306,17 +1307,7 @@
}
}
- // Use reflection to get Container.startLWModal.
- try {
- Method method = AccessController.doPrivileged(new ModalPrivilegedAction(
- Container.class, "startLWModal"));
- if (method != null) {
- method.invoke(dialog, (Object[])null);
- }
- } catch (IllegalAccessException ex) {
- } catch (IllegalArgumentException ex) {
- } catch (InvocationTargetException ex) {
- }
+ AWTAccessor.getContainerAccessor().startLWModal(dialog);
if (parentComponent instanceof JInternalFrame) {
try {
@@ -1451,17 +1442,7 @@
}
}
- // Use reflection to get Container.startLWModal.
- try {
- Method method = AccessController.doPrivileged(new ModalPrivilegedAction(
- Container.class, "startLWModal"));
- if (method != null) {
- method.invoke(dialog, (Object[])null);
- }
- } catch (IllegalAccessException ex) {
- } catch (IllegalArgumentException ex) {
- } catch (InvocationTargetException ex) {
- }
+ AWTAccessor.getContainerAccessor().startLWModal(dialog);
if (parentComponent instanceof JInternalFrame) {
try {
@@ -1535,18 +1516,7 @@
if (iFrame.isVisible() &&
event.getSource() == JOptionPane.this &&
event.getPropertyName().equals(VALUE_PROPERTY)) {
- // Use reflection to get Container.stopLWModal().
- try {
- Method method = AccessController.doPrivileged(
- new ModalPrivilegedAction(
- Container.class, "stopLWModal"));
- if (method != null) {
- method.invoke(iFrame, (Object[])null);
- }
- } catch (IllegalAccessException ex) {
- } catch (IllegalArgumentException ex) {
- } catch (InvocationTargetException ex) {
- }
+ AWTAccessor.getContainerAccessor().stopLWModal(iFrame);
try {
iFrame.setClosed(true);
@@ -2512,33 +2482,6 @@
",wantsInput=" + wantsInputString;
}
- /**
- * Retrieves a method from the provided class and makes it accessible.
- */
- private static class ModalPrivilegedAction implements PrivilegedAction {
- private Class> clazz;
- private String methodName;
-
- public ModalPrivilegedAction(Class> clazz, String methodName) {
- this.clazz = clazz;
- this.methodName = methodName;
- }
-
- public Method run() {
- Method method = null;
- try {
- method = clazz.getDeclaredMethod(methodName, (Class[])null);
- } catch (NoSuchMethodException ex) {
- }
- if (method != null) {
- method.setAccessible(true);
- }
- return method;
- }
- }
-
-
-
///////////////////
// Accessibility support
///////////////////
diff -r f0bbc76584d7 -r 204ae465851d jdk/src/share/classes/sun/awt/AWTAccessor.java
--- a/jdk/src/share/classes/sun/awt/AWTAccessor.java Tue Apr 01 01:59:59 2014 +0400
+++ b/jdk/src/share/classes/sun/awt/AWTAccessor.java Tue Apr 01 13:56:07 2014 +0400
@@ -272,6 +272,16 @@
* bypasses disabled Components during the search.
*/
Component findComponentAt(Container cont, int x, int y, boolean ignoreEnabled);
+
+ /**
+ * Starts LW Modal.
+ */
+ void startLWModal(Container cont);
+
+ /**
+ * Starts LW Modal.
+ */
+ void stopLWModal(Container cont);
}
/*