What changed, and why it matters
This commit fixes a simple but important logic bug in a Dart helper class. The code was checking whether a function was null, but then doing the exact opposite of what it should: when the function existed, it did nothing; when it was missing, it tried to call the missing function and would have crashed. The fix flips the condition so the existing function is called and the alternative code path is used only when arguments are needed. The bug appears to be a plain coding mistake rather than a deliberate security flaw, but in a wallet app any crash or unexpected behavior during sensitive operations is worth treating carefully.
Review all call sites of IfNotAlreadyAsync to confirm the fix resolves previously observed crashes, and add unit tests covering both the `_function` and `_functionWithArgs` code paths. Because this is a wallet application, also verify that no sensitive operation could have been interrupted or re-entered due to the exception path.
Security signals we found
Null-dereference / assertion failure bug fixed
Logic inversion in guard class that could cause runtime exceptions
Concurrency guard class: misuse could affect re-entrancy-sensitive wallet operations
Evidence from the diff
In lib/utilities/if_not_already.dart the IfNotAlreadyAsync class guards an async function so it is not executed concurrently. The original code read if (_function == null) { await _function!(); } else { await _functionWithArgs!(args); }. Because _function is non-nullable, the null branch would only be taken when the field was actually populated, and the bang operator would then assert it was non-null, producing a runtime assertion failure. Conversely, when _function was null, the else branch would force-call _functionWithArgs!, likely also throwing. The patch changes the condition to if (_function != null) and removes the unnecessary bang, restoring the intended behavior: call the no-argument function if present, otherwise call the function-with-args variant.
Changed components
lib/utilities/if_not_already.dartIfNotAlreadyAsync helper classInspect captured patch +2 / −2
diff --git a/lib/utilities/if_not_already.dart b/lib/utilities/if_not_already.dart
index 41da52c..8a2a040 100644
--- a/lib/utilities/if_not_already.dart
+++ b/lib/utilities/if_not_already.dart
@@ -31,8 +31,8 @@ class IfNotAlreadyAsync<T> {
if (!_locked) {
_locked = true;
try {
- if (_function == null) {
- await _function!();
+ if (_function != null) {
+ await _function();
} else {
await _functionWithArgs!(args);
}
Why this scored 42/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.