7201064: Better dialogue checking
authordenis
Fri, 30 Nov 2012 15:51:44 +0400
changeset 16099 fb978a77b3e7
parent 16098 9001e536ab4e
child 16100 379f48d34516
7201064: Better dialogue checking Reviewed-by: serb, skoivu
jdk/src/share/classes/java/awt/Dialog.java
--- a/jdk/src/share/classes/java/awt/Dialog.java	Mon Nov 26 22:49:06 2012 -0800
+++ b/jdk/src/share/classes/java/awt/Dialog.java	Fri Nov 30 15:51:44 2012 +0400
@@ -39,6 +39,7 @@
 import sun.awt.util.IdentityArrayList;
 import sun.awt.util.IdentityLinkedList;
 import sun.security.util.SecurityConstants;
+import java.security.AccessControlException;
 
 /**
  * A Dialog is a top-level window with a title and a border
@@ -128,6 +129,8 @@
      */
     boolean undecorated = false;
 
+    private transient boolean initialized = false;
+
     /**
      * Modal dialogs block all input to some top-level windows.
      * Whether a particular window is blocked depends on dialog's type
@@ -671,6 +674,7 @@
         this.title = title;
         setModalityType(modalityType);
         SunToolkit.checkAndSetPolicy(this);
+        initialized = true;
     }
 
     /**
@@ -722,6 +726,7 @@
         this.title = title;
         setModalityType(modalityType);
         SunToolkit.checkAndSetPolicy(this);
+        initialized = true;
     }
 
     /**
@@ -851,12 +856,9 @@
         if (modalityType == type) {
             return;
         }
-        if (type == ModalityType.TOOLKIT_MODAL) {
-            SecurityManager sm = System.getSecurityManager();
-            if (sm != null) {
-                sm.checkPermission(SecurityConstants.AWT.TOOLKIT_MODALITY_PERMISSION);
-            }
-        }
+
+        checkModalityPermission(type);
+
         modalityType = type;
         modal = (modalityType != ModalityType.MODELESS);
     }
@@ -1025,6 +1027,11 @@
      */
     @Deprecated
     public void show() {
+        if (!initialized) {
+            throw new IllegalStateException("The dialog component " +
+                "has not been initialized properly");
+        }
+
         beforeFirstShow = false;
         if (!isModal()) {
             conditionalShow(null, null);
@@ -1600,18 +1607,50 @@
         }
     }
 
+    private void checkModalityPermission(ModalityType mt) {
+        if (mt == ModalityType.TOOLKIT_MODAL) {
+            SecurityManager sm = System.getSecurityManager();
+            if (sm != null) {
+                sm.checkPermission(
+                    SecurityConstants.AWT.TOOLKIT_MODALITY_PERMISSION
+                );
+            }
+        }
+    }
+
     private void readObject(ObjectInputStream s)
         throws ClassNotFoundException, IOException, HeadlessException
     {
         GraphicsEnvironment.checkHeadless();
-        s.defaultReadObject();
+
+        java.io.ObjectInputStream.GetField fields =
+            s.readFields();
+
+        ModalityType localModalityType = (ModalityType)fields.get("modalityType", null);
+
+        try {
+            checkModalityPermission(localModalityType);
+        } catch (AccessControlException ace) {
+            localModalityType = DEFAULT_MODALITY_TYPE;
+        }
 
         // in 1.5 or earlier modalityType was absent, so use "modal" instead
-        if (modalityType == null) {
+        if (localModalityType == null) {
+            this.modal = fields.get("modal", false);
             setModal(modal);
         }
 
+        this.resizable = fields.get("resizable", true);
+        this.undecorated = fields.get("undecorated", false);
+        this.title = (String)fields.get("title", "");
+        this.modalityType = localModalityType;
+
         blockedWindows = new IdentityArrayList();
+
+        SunToolkit.checkAndSetPolicy(this);
+
+        initialized = true;
+
     }
 
     /*