Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-2990 - Fixed potential exception in table column state persistence

dragonmacher3863ee1117d4
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/AbstractGTableModel.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/AbstractGTableModel.java
index b4bdd0643f..22b723530e 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/AbstractGTableModel.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/AbstractGTableModel.java
@@ -28,6 +28,8 @@ public abstract class AbstractGTableModel<T> extends AbstractTableModel
private List<T> lastSelectedObjects = new ArrayList<>();
+ private boolean isDisposed;
+
@Override
public T getRowObject(int row) {
List<T> data = getModelData();
@@ -77,7 +79,7 @@ public abstract class AbstractGTableModel<T> extends AbstractTableModel
}
/**
- * The default implementation of {@link TableModel#getValueAt(int, int)} that calls the
+ * The default implementation of {@link TableModel#getValueAt(int, int)} that calls the
* abstract {@link #getColumnValueForRow(Object, int)}.
*/
@Override
@@ -95,23 +97,23 @@ public abstract class AbstractGTableModel<T> extends AbstractTableModel
/**
* A convenience method to search for the index of a given
* row object <b>that is visible in the GUI</b>. The <i>visible</i> limitation is due to the
- * fact that the data searched is retrieved from {@link #getModelData()}, which may be
- * filtered.
- *
- * <p>Note: this operation is O(n). For quick lookups, consider using the sorted version
+ * fact that the data searched is retrieved from {@link #getModelData()}, which may be
+ * filtered.
+ *
+ * <p>Note: this operation is O(n). For quick lookups, consider using the sorted version
* of this class.
- *
+ *
* @param rowObject The object for which to search.
- * @return the index of the item in the data returned by
+ * @return the index of the item in the data returned by
*/
protected int getIndexForRowObject(T rowObject) {
return getIndexForRowObject(rowObject, getModelData());
}
/**
- * Returns the index for the given object in the given list; -1 when the item is not in
- * the list.
- *
+ * Returns the index for the given object in the given list; -1 when the item is not in
+ * the list.
+ *
* @param rowObject the item
* @param data the data
* @return the index
@@ -127,5 +129,14 @@ public abstract class AbstractGTableModel<T> extends AbstractTableModel
// subclass to override and call super
lastSelectedObjects.clear();
getModelData().clear();
+ isDisposed = true;
+ }
+
+ /**
+ * Returns true if {@link #dispose()} has been called
+ * @return true if {@link #dispose()} has been called
+ */
+ public boolean isDisposed() {
+ return isDisposed;
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/TableColumnModelState.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/TableColumnModelState.java
index 719a039671..2edce4c40d 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/TableColumnModelState.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/TableColumnModelState.java
@@ -39,13 +39,13 @@ import ghidra.util.task.SwingUpdateManager;
* possible.
* <p>
* The basic outline of how this class works:<br>
- *
+ *
* This class loads and save table column state via requests made by clients like the {@link GTable} or
* the {@link GTableColumnModel}. These requests are in response to direct users actions (like
- * showing a new column) or to table changes (like column resizing). There are few things that
- * make this code tricky. Namely, when a change notification comes from the subsystem and not
- * direct user intervention, we do not know if the change was motived by the user directly or
- * by programmatic table configuration. We would prefer to only save data when the user makes
+ * showing a new column) or to table changes (like column resizing). There are few things that
+ * make this code tricky. Namely, when a change notification comes from the subsystem and not
+ * direct user intervention, we do not know if the change was motived by the user directly or
+ * by programmatic table configuration. We would prefer to only save data when the user makes
* changes, but we can not always know the source of the change. For example, column resizing
* can happen due to user dragging or due to the table subsystem performing a column layout.
* <p>
@@ -56,7 +56,7 @@ import ghidra.util.task.SwingUpdateManager;
* For 1, we ignore all changes until the table has been shown for the first time. For 2, we use
* SwingUpdate managers.
* <p>
- * The complicated part is that we allow clients to add columns at any time. If they do so
+ * The complicated part is that we allow clients to add columns at any time. If they do so
* after the table has been made visible, then we cannot ignore the event like we do when the
* table has not yet been realized. In our world view, the uniqueness of a table is based upon
* it's class and its columns. Thus, when a column is added or removed, it becomes a different
@@ -164,9 +164,23 @@ public class TableColumnModelState implements SortListener {
return;
}
+ if (isTableModelDisposed()) {
+ // This can happen if a client manually disposes its model directly instead of calling
+ // GTable.dispose(). In that case, there is nothing to save.
+ return;
+ }
+
doSaveState(saveToXML());
}
+ private boolean isTableModelDisposed() {
+ TableModel tableModel = table.getUnwrappedTableModel();
+ if (tableModel instanceof AbstractGTableModel<?> gTableModel) {
+ return gTableModel.isDisposed();
+ }
+ return false;
+ }
+
private void doSaveState(Element xmlElement) {
PreferenceState preferenceState = new PreferenceState();
preferenceState.putXmlElement(XML_COLUMN_DATA, xmlElement);
@@ -313,6 +327,13 @@ public class TableColumnModelState implements SortListener {
private void doRestoreState() {
+ if (isTableModelDisposed()) {
+ // This can happen if a client manually disposes its model directly instead of calling
+ // GTable.dispose(). Not sure if this can happen, but since we buffer restore
+ // requests, it is possible.
+ return;
+ }
+
restoring = true;
try {