Skip to content

Commit 8e38852

Browse files
thymikeeclaude
andcommitted
fix(android): read a child that vanished mid-read as gone
AccessibilityNodeInfo.getChild can throw a NullPointerException from the framework's result integrity check when the child's window closes during the read, for example while an alert dialog closes after `alert accept`. The persistent helper session reported that as a capture failure, so the host force-killed the session, answered with a one-shot capture, and kept the session off for about 40 s. Treat the throw as the null that the framework answers for a vanished child. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9935ef5 commit 8e38852

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎android/snapshot-helper/src/main/java/com/callstack/agentdevice/snapshothelper/AccessibilityNodeReads.java‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,19 @@ static AccessibilityNodeInfo root(AccessibilityWindowInfo window) {
3030
return window.getRoot();
3131
}
3232

33+
/**
34+
* The child, or null when it is gone. When the child's window closes during the read, the
35+
* framework can throw a NullPointerException from its result integrity check instead of answering
36+
* null (seen on API 35 while an alert dialog closed), so that throw means the same as null.
37+
*/
3338
static AccessibilityNodeInfo child(AccessibilityNodeInfo node, int index) {
34-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
35-
return node.getChild(index, PREFETCH_STRATEGY);
39+
try {
40+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
41+
return node.getChild(index, PREFETCH_STRATEGY);
42+
}
43+
return node.getChild(index);
44+
} catch (NullPointerException vanished) {
45+
return null;
3646
}
37-
return node.getChild(index);
3847
}
3948
}

0 commit comments

Comments
 (0)