Skip to content

Conversation

@OS-pedrogustavobilro
Copy link
Collaborator

Description

Crash

kotlin.UninitializedPropertyAccessException: lateinit property camera has not been initialized
	at yxroq.lmgyo.jsqbx(OSBARCScannerActivity.kt:554)

This PR fixes the crash by:

  1. Making the variable nullable instead of lateinit
  2. Have null checks before accessing it to make changes
  3. For read properties like flash and min/max zoom, hoisted them out of their composable functions to a single UI state (as recommended from Jetpack Compose docs), that gets updated when camera finishes initialization.
    a. This is actually something we that could improve in this native library in general - do not rely on composable functions accessing and changing variables declared in activity, instead have better separation of concerns between the UI and UI logic - but this is not something that will be addressed in this PR.

Context

https://outsystemsrd.atlassian.net/browse/RMET-4530

Type of changes

  • Fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Refactor (cosmetic changes)
  • Breaking change (change that would cause existing functionality to not work as expected)

Tests

Had to force a later initialization in the code for the crash to occur. Refer to the following test apps:

  1. Initialization delayed by 2 seconds - CRASH - Try with apk file and/or source code
  2. Initialization delayed by 2 seconds but containing fix from this PR - OK, you can notice that there's a delay in the torch and zoom buttons appear, but that's from the delayed initialization I placed to test, where 2 seconds is an extreme case, but the actual scanning can still work before the buttons appear - Try with apk file and/or source code
  3. With the same exact code from this PR - OK, no crash and there shouldn't be a noticeable delay in showing the torch / zoom buttons - Try with apk file and/or source code

@cssecautomation
Copy link

cssecautomation commented Oct 2, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

code/snyk check is complete. No issues have been found. (View Details)

@OS-pedrogustavobilro OS-pedrogustavobilro merged commit 98d4b8e into main Oct 2, 2025
4 of 5 checks passed
@OS-pedrogustavobilro OS-pedrogustavobilro deleted the fix/RMET-4530/crash-lateinit-var branch October 2, 2025 16:51
OS-pedrogustavobilro added a commit to OutSystems/cordova-outsystems-barcode that referenced this pull request Oct 2, 2025
`kotlin.UninitializedPropertyAccessException: lateinit property camera has not been initialized`

References:
- https://outsystemsrd.atlassian.net/browse/RMET-4530
- OutSystems/OSBarcodeLib-Android#52
OS-pedrogustavobilro added a commit to OutSystems/cordova-outsystems-barcode that referenced this pull request Oct 3, 2025
* fix(android): crash on lateinit var

`kotlin.UninitializedPropertyAccessException: lateinit property camera has not been initialized`

References:
- https://outsystemsrd.atlassian.net/browse/RMET-4530
- OutSystems/OSBarcodeLib-Android#52

* chore(release): prepare for 2.0.1 release
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.

5 participants