Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-7000 - Java 25 - Fixed a table exception due to disposal happening while components are still visible

dragonmacher098be6a9146c
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/AbstractStackEditorTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/AbstractStackEditorTest.java
index 3eca112ff2..1117bab2f0 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/AbstractStackEditorTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/AbstractStackEditorTest.java
@@ -151,6 +151,19 @@ public abstract class AbstractStackEditorTest extends AbstractEditorTest {
waitForSwing();// some editing notifications are in an invokeLater
}
+ protected void cleanup() {
+ clearActions();
+
+ Object editorPanel = getInstanceField("editorPanel", provider);
+ JTable table = (JTable) getInstanceField("table", editorPanel);
+ runSwing(() -> table.editingCanceled(new ChangeEvent(table)));
+ waitForSwing();// some editing notifications are in an invokeLater
+
+ runSwing(() -> {
+ provider.dispose();
+ }, true);
+ }
+
@Override
protected void setUpPlugins() throws PluginException {
super.setUpPlugins();
@@ -246,17 +259,6 @@ public abstract class AbstractStackEditorTest extends AbstractEditorTest {
}
}
- protected void cleanup() {
- clearActions();
-
- Object editorPanel = getInstanceField("editorPanel", provider);
- JTable table = (JTable) getInstanceField("table", editorPanel);
- runSwing(() -> table.editingCanceled(new ChangeEvent(table)));
- waitForSwing();// some editing notifications are in an invokeLater
-
- runSwing(() -> provider.dispose(), true);
- }
-
void clearActions() {
actions = null;
favorites.clear();
diff --git a/Ghidra/Features/FunctionGraph/src/main/java/ghidra/app/plugin/core/functiongraph/FGProvider.java b/Ghidra/Features/FunctionGraph/src/main/java/ghidra/app/plugin/core/functiongraph/FGProvider.java
index c1308d855c..79ccb1aa51 100644
--- a/Ghidra/Features/FunctionGraph/src/main/java/ghidra/app/plugin/core/functiongraph/FGProvider.java
+++ b/Ghidra/Features/FunctionGraph/src/main/java/ghidra/app/plugin/core/functiongraph/FGProvider.java
@@ -1062,6 +1062,7 @@ public class FGProvider extends VisualGraphComponentProvider<FGVertex, FGEdge, F
@Override
public void componentHidden() {
+ updateLocationUpdateManager.stop();
storeLocation(null);
controller.primaryProviderHidden();
super.componentHidden();
@@ -1071,10 +1072,11 @@ public class FGProvider extends VisualGraphComponentProvider<FGVertex, FGEdge, F
public void componentShown() {
super.componentShown();
- if (currentLocation == null) {
- return;
+ ProgramLocation loc = plugin.getProgramLocation();
+ storeLocation(loc);
+ if (loc != null) {
+ refreshAndResetPerspective();
}
- refreshAndResetPerspective();
}
@Override
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/ComponentPlaceholder.java b/Ghidra/Framework/Docking/src/main/java/docking/ComponentPlaceholder.java
index e9329f8f68..0b20ec2c64 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/ComponentPlaceholder.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/ComponentPlaceholder.java
@@ -95,8 +95,15 @@ public class ComponentPlaceholder {
}
/**
- * Returns the componentNode containing this placeholder
- * @return the node
+ * Sets the componentNode containing this placeholder
+ * @param node the component node containing this placeholder.
+ */
+ void setNode(ComponentNode node) {
+ compNode = node;
+ }
+
+ /**
+ * {@return the componentNode containing this placeholder}
*/
ComponentNode getNode() {
return compNode;
@@ -111,14 +118,6 @@ public class ComponentPlaceholder {
return showHeader;
}
- /**
- * Sets the componentNode containing this placeholder
- * @param node the component node containing this placeholder.
- */
- void setNode(ComponentNode node) {
- compNode = node;
- }
-
boolean isParented() {
return compNode != null;
}
@@ -198,8 +197,7 @@ public class ComponentPlaceholder {
* are restored from XML as being visible, but then no provider can be found for them.
*/
void reset() {
- isShowing = false;
- invalidate();
+ show(false);
}
/**
@@ -212,21 +210,46 @@ public class ComponentPlaceholder {
}
isShowing = doShow;
+
invalidate();
}
+ private void hideComponent() {
+ if (componentProvider == null) {
+ return;
+ }
+
+ JComponent component = componentProvider.getComponent();
+ if (component == null) {
+ return; // can happen during initialization
+ }
+
+ Container parent = component.getParent();
+ if (parent != null) {
+ parent.remove(component);
+ }
+ }
+
private void invalidate() {
+ // Hide the component provider's component before clearing the UI. If we later dispose the
+ // component provider and the component is still visible, it may get repainted after being
+ // disposed, which can trigger exceptions.
+ hideComponent();
invalidateComponentNode();
+ disposeDockableComponent();
+ notifyProviderVisibilityIsChanging();
+ }
- disposeComponent();
+ private void notifyProviderVisibilityIsChanging() {
+ if (componentProvider == null) {
+ return;
+ }
- if (componentProvider != null) {
- if (isShowing) {
- componentProvider.componentShown();
- }
- else {
- componentProvider.componentHidden();
- }
+ if (isShowing) {
+ componentProvider.componentShown();
+ }
+ else {
+ componentProvider.componentHidden();
}
}
@@ -235,14 +258,15 @@ public class ComponentPlaceholder {
}
void dispose() {
-
disposed = true;
+ disposeDockableComponent();
+ disposeNode();
+ }
- if (comp != null) {
- comp.dispose();
- comp = null;
- }
-
+ /**
+ * Performs a final removal of this placeholder from its {@link ComponentNode}.
+ */
+ private void disposeNode() {
if (compNode == null) {
return;
}
@@ -256,7 +280,11 @@ public class ComponentPlaceholder {
compNode = null;
}
- private void disposeComponent() {
+ /**
+ * Disposes the active {@link DockableComponent}. The component may later get recreated in the
+ * call to {@link #getComponent()}.
+ */
+ private void disposeDockableComponent() {
if (comp == null) {
return;
}
@@ -345,6 +373,7 @@ public class ComponentPlaceholder {
if (compNode != null) {
isDocking = compNode.winMgr.isDocking();
}
+
if (comp == null && isShowing) {
comp = new DockableComponent(this, isDocking);
}
@@ -450,7 +479,7 @@ public class ComponentPlaceholder {
updateInfo(newProvider);
}
- disposeComponent();
+ disposeDockableComponent();
}
public void update() {
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/RootNode.java b/Ghidra/Framework/Docking/src/main/java/docking/RootNode.java
index ff23bed0b5..13624cd4e4 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/RootNode.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/RootNode.java
@@ -277,7 +277,8 @@ class RootNode extends WindowNode {
}
child.parent = this;
}
- placeholder.getNode().add(placeholder);
+
+ node.add(placeholder);
}
/**
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTableColumnModel.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTableColumnModel.java
index 7f3755a1c5..7610c9e87a 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTableColumnModel.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTableColumnModel.java
@@ -587,13 +587,27 @@ public class GTableColumnModel
@Override
public void propertyChange(PropertyChangeEvent evt) {
+
String name = evt.getPropertyName();
- if ("width".equals(name) || "preferredWidth".equals(name)) {
- invalidateWidthCache();
- // This is a misnomer, we're using this method simply to cause a relayout
- fireColumnMarginChanged();
- columnModelState.saveState();
+ if (!("width".equals(name) || "preferredWidth".equals(name))) {
+ return;
}
+
+ invalidateWidthCache();
+ columnModelState.saveState();
+
+ if (table.isEditing()) {
+ // Calling fireColumnMarginChanged() while the table is editing will end the edit. The
+ // assumption is that we really only want to trigger a relayout if the column sizes are
+ // changing programmatically. We may get a propertyChange() callback related to 'width'
+ // and 'preferredWidth' when the is trying to initiate an edit. Handle that case by
+ // ignoring the callback with an active edit.
+ return;
+ }
+
+ // This is a misnomer, we're using this method simply to cause a relayout
+ fireColumnMarginChanged();
+
}
@Override