Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-5326 fixed junit tests and removed check for default field names

ghidragon9429fa0a8e62
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/EditDataFieldDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/EditDataFieldDialog.java
index bc2051480e..e9f4450e2b 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/EditDataFieldDialog.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/EditDataFieldDialog.java
@@ -138,7 +138,7 @@ public class EditDataFieldDialog extends DialogComponentProvider {
private void initializeFields() {
String name = component.getFieldName();
if (StringUtils.isBlank(name)) {
- name = component.getDefaultFieldName();
+ name = "";
}
nameField.setText(name);
commentField.setText(component.getComment());
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/data/EditFieldDialogTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/data/EditFieldDialogTest.java
index 8fab4338eb..adcd62d4d1 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/data/EditFieldDialogTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/data/EditFieldDialogTest.java
@@ -123,7 +123,7 @@ public class EditFieldDialogTest extends AbstractGhidraHeadedIntegrationTest {
goTo(0x101);
showFieldEditDialog();
assertNull(structure.getComponent(1).getFieldName());
- assertEquals("field1_0x1", getNameText());
+ assertEquals("", getNameText());
setNameText("abc");
@@ -162,23 +162,6 @@ public class EditFieldDialogTest extends AbstractGhidraHeadedIntegrationTest {
assertEquals("byte", structure.getComponent(1).getDataType().getDisplayName());
}
- @Test
- public void testRenameToDuplicateNameError() {
- goTo(0x104);
- showFieldEditDialog();
- assertEquals("count", structure.getComponent(4).getFieldName());
- assertEquals("count", getNameText());
-
- setNameText("color");
-
- pressOk();
- waitForTasks();
- assertTrue(isDialogVisible());
- assertEquals("Duplicate field name", getDialogStatusText());
-
- assertEquals("count", structure.getComponent(4).getFieldName());
- }
-
private boolean isDialogVisible() {
return runSwing(() -> dialog.isVisible());
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeComponent.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeComponent.java
index 796726c932..77dc9442cb 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeComponent.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeComponent.java
@@ -117,8 +117,10 @@ public interface DataTypeComponent {
*
* @param fieldName the new field name for this component.
*
- * @throws DuplicateNameException if another component of the parent has
- * the specified field name.
+ * @throws DuplicateNameException This is actually never thrown anymore. All the other ways
+ * of naming fields did not perform this check and it would cause quite a bit of churn to
+ * add that exception to all the other methods that affect field names. So to be consistent,
+ * we no longer do the check in this method.
*/
public void setFieldName(String fieldName) throws DuplicateNameException;
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/InternalDataTypeComponent.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/InternalDataTypeComponent.java
index 2dd6fbc2d7..f2bcc5eb5e 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/InternalDataTypeComponent.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/InternalDataTypeComponent.java
@@ -64,7 +64,7 @@ public interface InternalDataTypeComponent extends DataTypeComponent {
public default String cleanupFieldName(String name) {
// For now, silently convert whitespace to underscores
String fieldName = StringUtilities.whitespaceToUnderscores(name);
- if (StringUtils.isBlank(fieldName) || fieldName.equals(getDefaultFieldName())) {
+ if (StringUtils.isBlank(fieldName)) {
fieldName = null;
}
return fieldName;