Merge remote-tracking branch

'origin/GP-3145-dragonmacher-help-viewer-exception' (Closes #7010,
Closes #7016, Closes #6048)
This commit is contained in:
Ryan Kurtz 2024-10-09 09:33:58 -04:00
commit 1a944fd96a

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -22,6 +22,7 @@ import java.rmi.ConnectException;
import ghidra.util.Msg;
import ghidra.util.SystemUtilities;
import ghidra.util.exception.ClosedException;
import utilities.util.reflection.ReflectionUtilities;
/**
* Class to handle exceptions caught within the Swing event dispatch thread.
@ -52,15 +53,7 @@ public class SwingExceptionHandler implements UncaughtExceptionHandler {
t = t.getCause();
}
if (t instanceof ThreadDeath) {
return;
}
if (t instanceof ConnectException) {
return;
}
if (t instanceof ClosedException) {
if (shouldIgnore(t)) {
return;
}
@ -81,6 +74,58 @@ public class SwingExceptionHandler implements UncaughtExceptionHandler {
t);
}
private static boolean shouldIgnore(Throwable t) {
if (t instanceof ThreadDeath) {
return true;
}
if (t instanceof ConnectException) {
return true;
}
if (t instanceof ClosedException) {
return true;
}
if (isKnownJavaHelpException(t)) {
return true;
}
return false;
}
private static boolean isKnownJavaHelpException(Throwable t) {
String stackString = ReflectionUtilities.stackTraceToString(t);
if (stackString.contains("com.sun.java.help.impl.JHelpPrintHandler$JHFrame.validate")) {
// This happens in the Java Help API when trying to print. We do not have license to
// change that code, so squash the exception here. Printing still seems to work as
// expected.
return true;
}
//
// There is an exception(s) that happens if the user has shown the Help Window and then
// switches themes. This exception is harder to test for, since it has not stack elements
// specific to the help API. Below are some (hopefully) help-specific stack elements that
// we can use to filter out this exception(s).
//
if (stackString.contains("javax.help.plaf.basic.BasicTOCNavigatorUI")) {
return true;
}
if (stackString.contains("javax.swing.text.html.BlockView") &&
stackString.contains("javax.swing.text.html.HTMLDocument.fireChangedUpdate")) {
// Log a message since this type of exception may happen outside of the help system. It
// may help developers to see this in the console.
Msg.debug(SwingExceptionHandler.class, "Squashed an assumed help exception");
return true;
}
return false;
}
@Override
public void uncaughtException(Thread t, Throwable e) {
handleUncaughtException(e);