From a882e190ef71343d08ffdd6de24b66e4bebf7cf5 Mon Sep 17 00:00:00 2001 From: thc202 Date: Fri, 22 Apr 2016 23:53:30 +0100 Subject: [PATCH] Fix InterruptedException while stopping the spider Append the messages to output tab and add the messages to History tab asynchronously in the EDT, preventing the exceptions (and "hanging" the spider worker threads more time than needed). More detailed changes: - AuthenticationHelper, append the authentication status messages to the OutputPanel and add the authentication messages to the ExtensionHistory, asynchronously (for the latter also check if the View is initialised, otherwise there's no point adding it); - OutputPanel, add a convenience method that adds a message asynchronously to the panel itself. Fix #2429 - InterruptedExceptions while stopping the spider with user authentication --- .../parosproxy/paros/view/OutputPanel.java | 17 +++++++++++++ .../authentication/AuthenticationHelper.java | 24 +++++++++++++------ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/org/parosproxy/paros/view/OutputPanel.java b/src/org/parosproxy/paros/view/OutputPanel.java index 5bd5735c242..c0ac08880a2 100644 --- a/src/org/parosproxy/paros/view/OutputPanel.java +++ b/src/org/parosproxy/paros/view/OutputPanel.java @@ -214,4 +214,21 @@ private void doAppend(String message){ getTxtOutput().append(message); } + /** + * Appends the given {@code message} to the panel, asynchronously in the EDT. + * + * @param message the message to append to the output panel + * @since TODO add version + * @see EventQueue#invokeLater(Runnable) + */ + public void appendAsync(final String message) { + EventQueue.invokeLater(new Runnable() { + + @Override + public void run() { + doAppend(message); + } + }); + } + } // @jve:decl-index=0:visual-constraint="10,10" diff --git a/src/org/zaproxy/zap/authentication/AuthenticationHelper.java b/src/org/zaproxy/zap/authentication/AuthenticationHelper.java index 84e3dc67061..11d0b7ca011 100644 --- a/src/org/zaproxy/zap/authentication/AuthenticationHelper.java +++ b/src/org/zaproxy/zap/authentication/AuthenticationHelper.java @@ -1,5 +1,6 @@ package org.zaproxy.zap.authentication; +import java.awt.EventQueue; import java.io.IOException; import org.apache.commons.httpclient.HttpState; @@ -57,7 +58,7 @@ public static void notifyOutputAuthSuccessful(HttpMessage msg) { // Let the user know it worked if (View.isInitialised()) { View.getSingleton().getOutputPanel() - .append(Constant.messages.getString("authentication.output.success") + "\n"); + .appendAsync(Constant.messages.getString("authentication.output.success") + "\n"); } } @@ -71,7 +72,7 @@ public static void notifyOutputAuthFailure(HttpMessage msg) { // Let the user know it failed if (View.isInitialised()) { View.getSingleton().getOutputPanel() - .append(Constant.messages.getString("authentication.output.failure") + "\n"); + .appendAsync(Constant.messages.getString("authentication.output.failure") + "\n"); } } @@ -84,13 +85,22 @@ public HttpState getCorrespondingHttpState() { public static void addAuthMessageToHistory(HttpMessage msg) { // Add message to history try { - HistoryReference ref = new HistoryReference(Model.getSingleton().getSession(), + final HistoryReference ref = new HistoryReference(Model.getSingleton().getSession(), HistoryReference.TYPE_AUTHENTICATION, msg); ref.addTag(HISTORY_TAG_AUTHENTICATION); - ExtensionHistory extHistory = Control.getSingleton().getExtensionLoader() - .getExtension(ExtensionHistory.class); - if (extHistory != null) { - extHistory.addHistory(ref); + if (View.isInitialised()) { + final ExtensionHistory extHistory = Control.getSingleton() + .getExtensionLoader() + .getExtension(ExtensionHistory.class); + if (extHistory != null) { + EventQueue.invokeLater(new Runnable() { + + @Override + public void run() { + extHistory.addHistory(ref); + } + }); + } } } catch (Exception ex) { log.error("Cannot add authentication message to History tab.", ex);