Skip to content

Fix decode-screen NPE crash when a message has a null destination call - #609

Merged
patrickrb merged 1 commit into
devfrom
optio/task-655d82f1-29d2-4037-bd92-c8fc0b2b3057
Jul 22, 2026
Merged

Fix decode-screen NPE crash when a message has a null destination call#609
patrickrb merged 1 commit into
devfrom
optio/task-655d82f1-29d2-4037-bd92-c8fc0b2b3057

Conversation

@patrickrb

Copy link
Copy Markdown
Owner

Root cause

Ft8Message.checkIsCQ() dereferenced callsignTo before its guard, and the guard checked the wrong variable:

String s = callsignTo.trim().split(" ")[0];   // NPE here when callsignTo == null
if (s == null) { return false; }              // dead: String.split()[0] is never null

callsignTo defaults to null (public String callsignTo = null) and stays null for free-text/telemetry frames and unresolved-hash decodes that still reach the published decode list. The if (s == null) check is dead — String.split()[0] never returns null — so the intended "missing destination → not a CQ" behaviour never actually protected the real deref.

Impact (live main-thread crash on the primary screen)

The Compose decode screen calls checkIsCQ() unconditionally on the main thread with no try/catch:

  • DecodeRow.kt:72 — for every rendered decode row
  • DecodeRow.kt:352 — inside resolveQsoStatus(...)
  • DecodeScreen.kt:479, 511, 515 — inside filterMessages(...) ("Show only CQ", "CQ Calls", "New DXCC")

A single decode with a null callsignTo therefore crashed the whole app on the app's primary screen.

This is proven reachable by the existing #254 guard already present in ActiveQsoPanel.kt:104:

// Guard: checkIsCQ() calls callsignTo.trim() which NPEs on null. (#254)
if (msg.callsignTo != null && msg.checkIsCQ()) return@forEach

ActiveQsoPanel is a sibling consumer of the same mainViewModel.mutableFt8MessageList. That guard was added there but not to the decode-list consumers, which have the identical deref.

Fix

Null-guard callsignTo inside checkIsCQ() itself — the single choke point every caller funnels through — so a missing destination returns "not a CQ" instead of throwing. This covers DecodeRow, resolveQsoStatus, filterMessages, and MapScreen at once. Behaviour is byte-for-byte unchanged for any message that has a callsignTo.

Testing performed

  • Added Ft8MessageTest.checkIsCQ_falseWhenCallsignToNull — reproduces the NPE against the unfixed code (java.lang.NullPointerException), passes after the fix.
  • :app:testDebugUnitTest — full unit suite green.
  • :app:assembleDebug — clean APK build across all 4 ABIs.

Risk

Minimal. One-line defensive null-guard in a leaf helper; no protocol/DSP/threading behaviour changes; no change for well-formed messages.

🤖 Generated with Claude Code

…call

Ft8Message.checkIsCQ() dereferenced callsignTo (callsignTo.trim().split(...))
before its guard, and that guard checked the wrong variable: `if (s == null)`
after `String s = callsignTo.trim().split(" ")[0]` is dead, because
String.split()[0] is never null. The value that can actually be null is
callsignTo itself — it defaults to null and stays null for free-text/telemetry
frames and unresolved-hash decodes that still reach the published decode list.

The Compose decode screen calls checkIsCQ() unconditionally on the main thread
with no try/catch — DecodeRow (every rendered row), resolveQsoStatus, and
DecodeScreen.filterMessages — so such a message crashed the whole app on the
primary screen. This is proven reachable by the existing #254 guard in
ActiveQsoPanel (`if (msg.callsignTo != null && msg.checkIsCQ())`), a sibling
consumer of the same mainViewModel.mutableFt8MessageList; that guard was added
to ActiveQsoPanel but not to the decode-list consumers.

Root-cause fix: null-guard callsignTo inside checkIsCQ() itself, the single
choke point through which every caller funnels, so a missing destination is
treated as "not a CQ" instead of throwing. Behaviour is unchanged for every
message that has a callsignTo.

Test: Ft8MessageTest.checkIsCQ_falseWhenCallsignToNull (throws NPE before the
fix, passes after). Full :app:testDebugUnitTest and :app:assembleDebug (all
4 ABIs) verified green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 36.62%. Comparing base (adf04bb) to head (8528cff).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##                dev     #609   +/-   ##
=========================================
  Coverage     36.62%   36.62%           
  Complexity      197      197           
=========================================
  Files           216      216           
  Lines         26885    26885           
  Branches       3294     3294           
=========================================
  Hits           9847     9847           
  Misses        16811    16811           
  Partials        227      227           
Flag Coverage Δ
android 15.03% <ø> (ø)
native 9.93% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a crash in the decode UI path by making Ft8Message.checkIsCQ() null-safe when callsignTo is missing (which can occur for free-text/telemetry/unresolved-hash decodes that still reach the rendered decode list).

Changes:

  • Add a defensive callsignTo == null guard inside Ft8Message.checkIsCQ() to return false instead of throwing.
  • Add a unit test ensuring checkIsCQ() returns false (and does not NPE) when callsignTo is left at its default null.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
ft8af/app/src/main/java/com/k1af/ft8af/Ft8Message.java Makes checkIsCQ() resilient to callsignTo == null, preventing main-thread crashes in UI callers.
ft8af/app/src/test/java/com/k1af/ft8af/Ft8MessageTest.java Adds regression coverage for the null-destination case to prevent reintroducing the crash.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@patrickrb
patrickrb merged commit f388d6c into dev Jul 22, 2026
18 checks passed
@patrickrb
patrickrb deleted the optio/task-655d82f1-29d2-4037-bd92-c8fc0b2b3057 branch July 22, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants