Ghidra is a software reverse engineering (SRE) framework
GP-2711 - Bundles - Added code to prevent error reporting when disposing the tool
dragonmacherb5e76efcbf51
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.javaindex 0933ec6814..67d27bef6b 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java@@ -62,11 +62,12 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {private GhidraFileChooser fileChooser;private GhidraFileFilter filter;private final BundleHost bundleHost;+ private transient boolean isDisposed;/*** {@link BundleStatusComponentProvider} visualizes bundle status and exposes actions for* adding, removing, enabling, disabling, activating, and deactivating bundles.- *+ ** @param tool the tool* @param owner the owner name* @param bundleHost the bundle host@@ -187,7 +188,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {/*** get the currently selected rows and translate to model rows- *+ ** @return selected model rows*/int[] getSelectedModelRows() {@@ -290,8 +291,16 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {Collection<GhidraBundle> bundles = bundleHost.add(resourceFiles, true, false);TaskLauncher.launchNonModal("Activating new bundles", (monitor) -> {- bundleHost.activateAll(bundles, monitor,- getTool().getService(ConsoleService.class).getStdErr());+ try {+ bundleHost.activateAll(bundles, monitor,+ getTool().getService(ConsoleService.class).getStdErr());+ }+ catch (Exception e) {+ if (!isDisposed) {+ Msg.showError(this, bundleStatusTable, "Error Activating Bundles",+ "Unexpected error activating new bundles", e);+ }+ }});}}@@ -340,6 +349,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {}public void dispose() {+ isDisposed = true;filterPanel.dispose();}@@ -348,11 +358,11 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {}/**- * This is for testing only! during normal execution, statuses are only added through+ * This is for testing only! during normal execution, statuses are only added through* BundleHostListener bundle(s) added events.- *+ ** <p>Each new bundle will be enabled and writable- *+ ** @param bundleFiles the files to use*/public void setBundleFilesForTesting(List<ResourceFile> bundleFiles) {@@ -363,7 +373,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {//=================================================================================================// Inner Classes-//=================================================================================================+//=================================================================================================private final class RemoveBundlesTask extends Task {private final DeactivateAndDisableBundlesTask deactivateBundlesTask;@@ -405,7 +415,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {/*** A task to enable and activate bundles.- *+ ** @param title the title* @param statuses the bundle statuses* @param inStages see {@link BundleHost#activateInStages}@@ -419,7 +429,18 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {@Overridepublic void run(TaskMonitor monitor) throws CancelledException {+ try {+ doRun(monitor);+ }+ catch (Exception e) {+ if (!isDisposed) {+ Msg.showError(this, bundleStatusTable, "Error Refreshing Bundles",+ "Unexpected error refreshing bundles", e);+ }+ }+ }+ private void doRun(TaskMonitor monitor) {List<GhidraBundle> bundles = new ArrayList<>();for (BundleStatus status : statuses) {GhidraBundle bundle = bundleHost.getExistingGhidraBundle(status.getFile());@@ -472,11 +493,15 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {monitor.setMaximum(bundles.size());for (GhidraBundle bundle : bundles) {+ monitor.checkCanceled();try {bundleHost.deactivateSynchronously(bundle.getLocationIdentifier());bundleHost.disable(bundle);}catch (GhidraBundleException | InterruptedException e) {+ if (isDisposed) {+ return; // the tool is being closed+ }Msg.error(this, "Error while deactivating and disabling bundle", e);}monitor.incrementProgress(1);@@ -485,7 +510,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {}/*- * Activating/deactivating a single bundle doesn't require resolving dependents, so this task+ * Activating/deactivating a single bundle doesn't require resolving dependents, so this task* is slightly different from the others.*/private class ActivateDeactivateBundleTask extends Task {@@ -515,11 +540,17 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {}}catch (Exception e) {+ if (isDisposed) {+ return; // the tool is being closed+ }status.setSummary(e.getMessage());Msg.error(this, "Error during activation/deactivation of bundle", e);}finally {status.setBusy(false);+ if (isDisposed) {+ return; // the tool is being closed+ }notifyTableRowChanged(status);}}