fix potential npes resulting from get transactions
What changed, and why it matters
This commit fixes a bug where Sparrow Wallet could crash with a NullPointerException when it tried to process a Bitcoin transaction that it expected to receive from an Electrum server but did not actually get. The patch now checks if the transaction is missing, marks it as unfetchable, and skips it instead of crashing. It also adds a safety check so the wallet is not accessed when it is not available. This is a reliability fix that prevents the application from failing unexpectedly during transaction history loading.
Apply the patch. Monitor for any remaining unfetchable transaction edge cases and consider logging when an Electrum server returns incomplete transaction data. No immediate incident response is indicated unless crashes have been observed in production.
Security signals we found
NullPointerException mitigation in transaction retrieval
Missing transaction handling via UNFETCHABLE_BLOCK_TRANSACTION sentinel
Defensive null check added before wallet access
Potential denial-of-service via malformed or missing server response
Evidence from the diff
In ElectrumServer.java, references.get(reference) can return null if the transaction was not successfully fetched. The original code dereferenced the returned Transaction without a null check, leading to potential NullPointerExceptions. The patch adds an explicit null check: if transaction is null, it stores UNFETCHABLE_BLOCK_TRANSACTION in the transactionMap and removes matching references from checkReferences before continuing. Additionally, the fee recovery path now guards wallet access with wallet != null before calling wallet.getWalletTransaction(). These are defensive null-safety fixes in transaction retrieval logic.
Changed components
src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.javaElectrum server transaction synchronizationWallet transaction history/fee resolutionInspect captured patch +6 / −1
diff --git a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java
index 6671e43..9c54213 100644
--- a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java
+++ b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java
@@ -877,6 +877,11 @@ public class ElectrumServer {
for(BlockTransactionHash reference : references.keySet()) {
Transaction transaction = references.get(reference);
+ if(transaction == null) {
+ transactionMap.put(reference.getHash(), UNFETCHABLE_BLOCK_TRANSACTION);
+ checkReferences.removeIf(ref -> ref.getHash().equals(reference.getHash()));
+ continue;
+ }
Date blockDate = null;
if(reference.getHeight() > 0) {
@@ -890,7 +895,7 @@ public class ElectrumServer {
}
Long fee = reference.getFee();
- if(fee == null) {
+ if(fee == null && wallet != null) {
BlockTransaction cached = wallet.getWalletTransaction(reference.getHash());
if(cached != null && cached.getFee() != null) {
fee = cached.getFee();
Why this scored 35/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.