From 3606b3364d137a151b10b00d3b7f9c767c69c440 Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Mon, 7 Oct 2024 18:30:23 -0400 Subject: [PATCH] GP-3145 - Squash some known unfixable exceptions ecountered when using the Help Window --- .../java/ghidra/SwingExceptionHandler.java | 67 ++++++++++++++++--- 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/Ghidra/Framework/Gui/src/main/java/ghidra/SwingExceptionHandler.java b/Ghidra/Framework/Gui/src/main/java/ghidra/SwingExceptionHandler.java index 40ce8a5d9b..af9fd8e059 100644 --- a/Ghidra/Framework/Gui/src/main/java/ghidra/SwingExceptionHandler.java +++ b/Ghidra/Framework/Gui/src/main/java/ghidra/SwingExceptionHandler.java @@ -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);