From dd6e14f727cd90d5b7fb7ff38fdf768d3b4c05cb Mon Sep 17 00:00:00 2001 From: Fabio Picheli Date: Wed, 16 Sep 2026 13:52:32 +0200 Subject: [PATCH] fix: avoid NPE when SCAN_PARAMETERS intent extra is missing in onCreate 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 --- .../plugins/barcode/view/OSBARCScannerActivity.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt index 180c535..7ad45f5 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt @@ -169,7 +169,15 @@ class OSBARCScannerActivity : ComponentActivity() { cameraExecutor = Executors.newSingleThreadExecutor() - val parameters = IntentCompat.getSerializableExtra(intent, SCAN_PARAMETERS, OSBARCScanParameters::class.java)!! + val parameters = IntentCompat.getSerializableExtra(intent, SCAN_PARAMETERS, OSBARCScanParameters::class.java) + if (parameters == null) { + // SCAN_PARAMETERS can be missing if the OS recreates this activity without the + // original intent extras (e.g. process death while backgrounded during a scan). + Log.e(LOG_TAG, "Missing $SCAN_PARAMETERS intent extra, finishing activity") + setResult(OSBARCError.INVALID_PARAMETERS_ERROR.code) + finish() + return + } // possibly lock orientation, the screen is adaptive by default if (parameters.scanOrientation == ORIENTATION_PORTRAIT) {