diff --git a/netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java b/netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java --- a/netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java +++ b/netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java @@ -336,6 +336,11 @@ public class CertWarningPane extends Sec policyEditor.toFront(); policyEditor.repaint(); } + while (policyEditor.isPerformingFileIO()) { + // wait until the policy file has been read before adding a new codebase. + // this ensures that the current applet's codebase is the last added and + // will be selected when the editor appears + } policyEditor.addNewCodebase(file.getCodeBase().toString()); policyEditor.setVisible(true); policyMenu.setVisible(false); diff --git a/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java b/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java --- a/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java +++ b/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java @@ -181,6 +181,11 @@ public class PartiallySignedAppTrustWarn policyEditor.toFront(); policyEditor.repaint(); } + while (policyEditor.isPerformingFileIO()) { + // wait until the policy file has been read before adding a new codebase. + // this ensures that the current applet's codebase is the last added and + // will be selected when the editor appears + } policyEditor.addNewCodebase(file.getCodeBase().toString()); policyEditor.setVisible(true); policyMenu.setVisible(false); diff --git a/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java b/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java --- a/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java +++ b/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java @@ -166,6 +166,8 @@ public class PolicyEditor extends JFrame private CustomPolicyViewer cpViewer = null; private final WeakReference weakThis = new WeakReference(this); private MD5SumWatcher fileWatcher; + private FileLock fileLock = null; + private Thread ioThread = null; private final ActionListener okButtonAction, closeButtonAction, addCodebaseButtonAction, removeCodebaseButtonAction, openButtonAction, saveAsButtonAction, viewCustomButtonAction; @@ -816,7 +818,7 @@ public class PolicyEditor extends JFrame * "-file" command line flag, or if none given, comes from DeploymentConfiguration. */ private void openAndParsePolicyFile() { - new Thread() { + ioThread = new Thread() { @Override public void run() { if (!file.exists()) { @@ -853,7 +855,6 @@ public class PolicyEditor extends JFrame // Split on newlines, both \r\n and \n style, for platform-independence final String[] lines = contents.split("\\r?\\n+"); String codebase = ""; - final FileLock fileLock; try { fileLock = FileUtils.getFileLock(file.getAbsolutePath(), false, true); } catch (final FileNotFoundException e) { @@ -915,7 +916,8 @@ public class PolicyEditor extends JFrame OutputController.getLogger().log(e); } } - }.start(); + }; + ioThread.start(); } /** @@ -952,7 +954,7 @@ public class PolicyEditor extends JFrame if (!changesMade) { return; } - new Thread() { + ioThread = new Thread() { @Override public void run() { try { @@ -982,7 +984,6 @@ public class PolicyEditor extends JFrame sb.append("\n/* Generated by PolicyEditor at " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .format(Calendar.getInstance().getTime()) + " */" + System.getProperty("line.separator")); final Set enabledPermissions = new HashSet(); - FileLock fileLock = null; try { fileLock = FileUtils.getFileLock(file.getAbsolutePath(), false, true); } catch (final FileNotFoundException e) { @@ -1018,7 +1019,8 @@ public class PolicyEditor extends JFrame showCouldNotSaveDialog(); } } - }.start(); + }; + ioThread.start(); } /** @@ -1067,6 +1069,21 @@ public class PolicyEditor extends JFrame } /** + * @return the File this PolicyEditor is operating on + */ + public File getFile() { + return file; + } + + /** + * Determine if the PolicyEditor is currently reading or writing a policy file + * @return iff the policy file is currently being read or written + */ + public boolean isPerformingFileIO() { + return getFile() != null && ((ioThread != null && ioThread.isAlive()) || (fileLock != null && fileLock.isValid())); + } + + /** * Start a Policy Editor instance. * @param args "-file $FILENAME" and/or "-codebase $CODEBASE" are accepted flag/value pairs. * -file specifies a file path to be opened by the editor. If none is provided, the default