Skip to content

Ghidra is a software reverse engineering (SRE) framework

Test fixes for non-failing stack traces in log file

dragonmacherc8a4f7dcf76f
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/editor/EnumEditorPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/editor/EnumEditorPanel.java
index 48c12b49cc..f5a6be5794 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/editor/EnumEditorPanel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/editor/EnumEditorPanel.java
@@ -310,8 +310,10 @@ class EnumEditorPanel extends JPanel {
EnumCellRenderer cellRenderer = new EnumCellRenderer();
table.setRowHeight(table.getRowHeight() + 4);
table.setDefaultEditor(String.class, new EnumStringCellEditor());
- table.getColumnModel().getColumn(EnumTableModel.VALUE_COL).setCellEditor(
- new EnumLongCellEditor());
+ table.getColumnModel()
+ .getColumn(EnumTableModel.VALUE_COL)
+ .setCellEditor(
+ new EnumLongCellEditor());
table.setDefaultRenderer(String.class, cellRenderer);
add(createInfoPanel(), BorderLayout.SOUTH);
@@ -335,13 +337,17 @@ class EnumEditorPanel extends JPanel {
}
private void changed() {
- String name = nameField.getText();
+ String name = nameField.getText().trim();
+ if (name.length() == 0) {
+ return;
+ }
+
if (!name.equals(editedEnumDT.getName())) {
try {
editedEnumDT.setName(name);
}
catch (InvalidNameException e) {
- e.printStackTrace();
+ setStatusMessage("'" + name + "' is not a valid name");
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/FunctionTagLoader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/FunctionTagLoader.java
index 6cc4bc68a4..2fc0bc764b 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/FunctionTagLoader.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/FunctionTagLoader.java
@@ -41,8 +41,10 @@ public class FunctionTagLoader {
*
* @param tagFile tag file
* @return List list of function tags
+ * @throws IOException if there is an exception reading the file
+ * @throws SAXException if there is an exception parsing the file
*/
- protected static Set<FunctionTag> loadTags(File tagFile) {
+ protected static Set<FunctionTag> loadTags(File tagFile) throws SAXException, IOException {
return loadTags(new ResourceFile(tagFile));
}
@@ -56,16 +58,17 @@ public class FunctionTagLoader {
try {
return loadTags(Application.getModuleDataFile(moduleDataFilePath));
}
- catch (FileNotFoundException e) {
+ catch (SAXException | IOException e) {
Msg.error(FunctionTagLoader.class,
"Error loading function tags file from " + moduleDataFilePath, e);
}
return new HashSet<>();
}
- protected static Set<FunctionTag> loadTags(final ResourceFile tagDataFile) {
- Set<FunctionTag> tags = new HashSet<>();
+ protected static Set<FunctionTag> loadTags(final ResourceFile tagDataFile)
+ throws SAXException, IOException {
+ Set<FunctionTag> tags = new HashSet<>();
try {
ErrorHandler errHandler = new ErrorHandler() {
@Override
@@ -116,10 +119,6 @@ public class FunctionTagLoader {
Msg.error(FunctionTagLoader.class, "Error parsing function tags from " + tagDataFile,
e);
}
- catch (SAXException | IOException e) {
- Msg.error(FunctionTagLoader.class, "Error loading function tags from " + tagDataFile,
- e);
- }
return tags;
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/tags/FunctionTagLoaderTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/tags/FunctionTagLoaderTest.java
index 546162dd5f..7d45000009 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/tags/FunctionTagLoaderTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/tags/FunctionTagLoaderTest.java
@@ -18,7 +18,6 @@ package ghidra.app.plugin.core.function.tags;
import static org.junit.Assert.*;
import java.io.File;
-import java.io.IOException;
import java.nio.file.Files;
import java.util.HashSet;
import java.util.Set;
@@ -117,10 +116,14 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
public void testLoadTags_EmptyFile() throws Exception {
// Create file without contents
File xxeFile = createTempFileForTest();
- Set<FunctionTag> tags = FunctionTagLoader.loadTags(xxeFile);
- Set<FunctionTag> expectedTags = new HashSet<>();
- assertEquals(tags, expectedTags);
+ try {
+ FunctionTagLoader.loadTags(xxeFile);
+ fail("Did not get expected exception");
+ }
+ catch (Exception e) {
+ // good
+ }
}
@Test
@@ -140,10 +143,13 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
File xxeFile = createTempFileForTest();
xxeFile.delete();
- Set<FunctionTag> tags = FunctionTagLoader.loadTags(xxeFile);
-
- Set<FunctionTag> expectedTags = new HashSet<>();
- assertEquals(tags, expectedTags);
+ try {
+ FunctionTagLoader.loadTags(xxeFile);
+ fail("Did not get expected exception");
+ }
+ catch (Exception e) {
+ // good
+ }
}
@Test
@@ -151,10 +157,14 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
// Create file with contents
File xxeFile = createTempFileForTest();
Files.write(xxeFile.toPath(), FUNCTION_TAGS_MALFORMED_XML.getBytes());
- Set<FunctionTag> tags = FunctionTagLoader.loadTags(xxeFile);
- Set<FunctionTag> expectedTags = new HashSet<>();
- assertEquals(tags, expectedTags);
+ try {
+ FunctionTagLoader.loadTags(xxeFile);
+ fail("Did not get expected exception");
+ }
+ catch (Exception e) {
+ // good
+ }
}
@Test
@@ -163,7 +173,7 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
* located in Base/data/functionTags.xml
* @throws IOException
*/
- public void testLoadTags_XmlDefault() throws IOException {
+ public void testLoadTags_XmlDefault() throws Exception {
// Create file with contents
File xxeFile = createTempFileForTest();
@@ -184,7 +194,7 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
}
@Test
- public void testLoadTags_XmlHasBlankNameValue() throws IOException {
+ public void testLoadTags_XmlHasBlankNameValue() throws Exception {
// Create file with contents
File xxeFile = createTempFileForTest();
@@ -204,7 +214,7 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
}
@Test
- public void testLoadTags_XmlHasCommentValue() throws IOException {
+ public void testLoadTags_XmlHasCommentValue() throws Exception {
// Create file with contents
File xxeFile = createTempFileForTest();
@@ -225,7 +235,7 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
}
@Test
- public void testLoadTags_XmlNoCommentTag() throws IOException {
+ public void testLoadTags_XmlNoCommentTag() throws Exception {
// Create file with contents
File xxeFile = createTempFileForTest();
@@ -252,7 +262,7 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
*
* @throws IOException
*/
- public void testLoadTags_XmlNoNameTag() throws IOException {
+ public void testLoadTags_XmlNoNameTag() throws Exception {
// Create file with contents
File xxeFile = createTempFileForTest();
diff --git a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/test/DummyTool.java b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/test/DummyTool.java
index d4608056a8..1b0931a9dc 100644
--- a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/test/DummyTool.java
+++ b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/test/DummyTool.java
@@ -17,8 +17,7 @@ package ghidra.test;
import java.awt.Window;
import java.beans.PropertyChangeListener;
-import java.util.Collections;
-import java.util.Set;
+import java.util.*;
import javax.swing.*;
import javax.swing.event.ChangeListener;
@@ -34,8 +33,7 @@ import ghidra.framework.model.*;
import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.PluginEvent;
import ghidra.framework.plugintool.PluginTool;
-import ghidra.framework.plugintool.util.PluginClassManager;
-import ghidra.framework.plugintool.util.ServiceListener;
+import ghidra.framework.plugintool.util.*;
import ghidra.program.model.listing.Program;
public class DummyTool extends PluginTool {
@@ -451,4 +449,9 @@ public class DummyTool extends PluginTool {
public JFrame getToolFrame() {
return null;
}
+
+ @Override
+ public UndoRedoToolState getUndoRedoToolState(DomainObject domainObject) {
+ return new UndoRedoToolState(new ArrayList<>(), domainObject);
+ }
}