Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-0: Backport "Handle race condition in StackUnwinderTest" to 'patch'

Dana9275d885c0c
diff --git a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/stack/StackUnwinderTest.java b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/stack/StackUnwinderTest.java
index 979d64155e..aed9f41df5 100644
--- a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/stack/StackUnwinderTest.java
+++ b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/stack/StackUnwinderTest.java
@@ -1388,7 +1388,22 @@ public class StackUnwinderTest extends AbstractGhidraHeadedDebuggerGUITest {
public static HoverLocation findTokenLocation(DecompilerPanel decompilerPanel,
Function function, String tokText, String fieldText) {
DecompileResults results = waitForValue(() -> {
- ProgramLocation pLoc = decompilerPanel.getCurrentLocation();
+ ProgramLocation pLoc;
+ try {
+ pLoc = decompilerPanel.getCurrentLocation();
+ }
+ catch (NullPointerException e) {
+ /**
+ * HACK: There's an unlikely race condition where the layout controller has created
+ * the array of layouts but not fully populated it by the time we ask for the
+ * current location. This may cause a line we inspect to still have null in it and
+ * throw an NPE. Whatever. Just catch the thing and return null so that we try
+ * again. As far as I can tell, this is not indicative of a problem in production,
+ * because the controller won't issue an updated event until that array is fully
+ * populated.
+ */
+ return null;
+ }
if (!(pLoc instanceof DecompilerLocation dLoc)) {
return null;
}