/hg/icedtea-web: Fix PolicyEditor null file on save and exit

aazores at icedtea.classpath.org aazores at icedtea.classpath.org
Tue Jun 3 17:15:57 UTC 2014


changeset 23a84212d1db in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=23a84212d1db
author: Andrew Azores <aazores at redhat.com>
date: Tue Jun 03 13:15:50 2014 -0400

	Fix PolicyEditor null file on save and exit

	2014-06-03  Andrew Azores  <aazores at redhat.com>

	    Fix for PR1776, PolicyEditor attempting to save to null file location when
	    exiting editor and answering Yes to save changes first.
	    * netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
	    (quit): select file to save to using fileChooser if file is null
	    (policyEditorWindowQuit): new helper method for PolicyEditorWindow and
	    PolicyEditorFrame quit()


diffstat:

 ChangeLog                                                         |   9 +
 netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java |  48 +++++----
 2 files changed, 36 insertions(+), 21 deletions(-)

diffs (84 lines):

diff -r d87ee4e6e81a -r 23a84212d1db ChangeLog
--- a/ChangeLog	Tue Jun 03 09:52:23 2014 -0400
+++ b/ChangeLog	Tue Jun 03 13:15:50 2014 -0400
@@ -1,3 +1,12 @@
+2014-06-03  Andrew Azores  <aazores at redhat.com>
+
+	Fix for PR1776, PolicyEditor attempting to save to null file location when
+	exiting editor and answering Yes to save changes first.
+	* netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
+	(quit): select file to save to using fileChooser if file is null 
+	(policyEditorWindowQuit): new helper method for PolicyEditorWindow and
+	PolicyEditorFrame quit()
+
 2014-06-03  Lukasz Dracz  <ldracz at redhat.com>
 
 	Changed Temporary Permissions from menu items to check box menu items
diff -r d87ee4e6e81a -r 23a84212d1db netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
--- a/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java	Tue Jun 03 09:52:23 2014 -0400
+++ b/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java	Tue Jun 03 13:15:50 2014 -0400
@@ -470,19 +470,35 @@
 
         @Override
         public void quit() {
-            if (editor.changesMade) {
-                final int save = JOptionPane.showConfirmDialog(this, R("PESaveChanges"));
-                if (save == JOptionPane.YES_OPTION) {
-                    editor.savePolicyFile();
-                } else if (save == JOptionPane.CANCEL_OPTION) {
-                    return;
+            policyEditorWindowQuit(this);
+        }
+    }
+
+    /*
+     * Casting a Window to PolicyEditorWindow is not generally safe - be sure that
+     * the argument passed to this method is actually a PolicyEditorDialog or PolicyEditorFrame.
+     */
+    private static void policyEditorWindowQuit(final Window window) {
+        final PolicyEditor editor = ((PolicyEditorWindow) window).getPolicyEditor();
+        if (editor.changesMade) {
+            final int save = JOptionPane.showConfirmDialog(window, R("PESaveChanges"));
+            if (save == JOptionPane.YES_OPTION) {
+                if (editor.policyFile.getFile() == null) {
+                    final int choice = editor.fileChooser.showSaveDialog(window);
+                    if (choice == JFileChooser.APPROVE_OPTION) {
+                        editor.policyFile.setFile(editor.fileChooser.getSelectedFile());
+                    } else if (choice == JFileChooser.CANCEL_OPTION) {
+                        return;
+                    }
                 }
+                editor.savePolicyFile();
+            } else if (save == JOptionPane.CANCEL_OPTION) {
+                return;
             }
-            editor.weakThis.clear();
-            editor.setClosed();
-            dispose();
         }
-
+        editor.weakThis.clear();
+        editor.setClosed();
+        window.dispose();
     }
 
     public static PolicyEditorWindow getPolicyEditorFrame(final String filepath) {
@@ -535,17 +551,7 @@
 
         @Override
         public void quit() {
-            if (editor.changesMade) {
-                final int save = JOptionPane.showConfirmDialog(this, R("PESaveChanges"));
-                if (save == JOptionPane.YES_OPTION) {
-                    editor.savePolicyFile();
-                } else if (save == JOptionPane.CANCEL_OPTION) {
-                    return;
-                }
-            }
-            editor.weakThis.clear();
-            editor.setClosed();
-            dispose();
+            policyEditorWindowQuit(this);
         }
     }
 


More information about the distro-pkg-dev mailing list