Skip to content

Commit 1c10534

Browse files
Fix: InfiniteContainer refresh race condition (#4343)
Fixed #3490 Added a guard clause to `refreshImpl` in `InfiniteContainer` to prevent re-entrant calls when a refresh is already in progress. This fixes an issue where rapid pull-to-refresh actions could cause the container's content (specifically when containing a single item) to disappear temporarily due to race conditions during the removal and addition of components. Also wrapped the user-defined `fetchComponents` call in a try-catch block to ensure the `requestingResults` flag is correctly reset even if an exception occurs, preventing the container from becoming stuck in a loading state. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 5cbcf9c commit 1c10534

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

CodenameOne/src/com/codename1/ui/InfiniteContainer.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,17 @@ public void run() {
124124
}
125125

126126
void refreshImpl() {
127+
if (requestingResults) {
128+
return;
129+
}
127130
requestingResults = true;
128-
Component[] components = fetchComponents(0, amount);
131+
Component[] components;
132+
try {
133+
components = fetchComponents(0, amount);
134+
} catch(RuntimeException err) {
135+
requestingResults = false;
136+
throw err;
137+
}
129138
if (components == null) {
130139
components = new Component[0];
131140
}

0 commit comments

Comments
 (0)