Conversation
OSBARCScannerActivity.onCreate unwrapped the SCAN_PARAMETERS IntentCompat.getSerializableExtra result with `!!`, so any launch of this Activity without that extra crashed with an unhandled NullPointerException before any other code ran. This has been observed in production consumer apps as a low-volume, non-deterministic crash, consistent with the OS recreating this (non-root) Activity in the background without the original custom Intent extra (e.g. after process death while a scan was in progress). Handle the missing-extra case the same way every other failure path in this Activity already does: finish with OSBARCError.INVALID_PARAMETERS_ERROR instead of crashing. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
picheli20
requested review from
andredestro and
markemer
and removed request for
a team
September 16, 2026 12:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
OSBARCScannerActivity.onCreatereads theSCAN_PARAMETERSintent extra viaIntentCompat.getSerializableExtra(...)!!. If that extra is ever absent whenonCreateruns, the!!throws an unhandledNullPointerExceptionbefore anything else executes, crashing the host app.This PR replaces the unchecked
!!with a null check that finishes the Activity gracefully withOSBARCError.INVALID_PARAMETERS_ERROR, mirroring how every other failure path in this Activity already reports errors (cancel, permission denied, scan error) viasetResult(error.code)+finish().Context
We're seeing this crash in production (via Crashlytics) in a consumer app using
@capacitor/barcode-scanner3.1.1 (which pinsionbarcode-android2.1.1): low-volume, non-deterministic, no repro from our own call site (we always pass a well-formedOSBARCScanParameters). It's consistent with the OS recreating this non-root Activity (e.g. after process death while backgrounded mid-scan) without restoring the original custom Intent extra.We can't fix this from the consumer app since the unchecked cast lives in this library. This change doesn't address why the extra can go missing (that's an Android platform-level activity-recreation edge case), but it stops it from being a hard crash and turns it into the same graceful failure path already used elsewhere in this file.
Type of changes
Tests
Manual: confirmed via bytecode/source inspection that this is the exact crash site (matches the reported
NullPointerException: null cannot be cast to non-null type com.outsystems.plugins.barcode.model.OSBARCScanParameters). No existing unit/instrumented tests coverOSBARCScannerActivity.onCreate, so none were touched; happy to add a test if you can point me at the preferred testing approach for this Activity (Compose/instrumented).Screenshots (if appropriate)
N/A (no UI change; the missing-parameters path now finishes the Activity instead of crashing)
Checklist
🤖 Generated with Claude Code