Skip to content

OpenTelemetryRumBuilder - Use lateinit vars instead of nullable/lazy.#1771

Open
breedx-splk wants to merge 1 commit into
open-telemetry:mainfrom
breedx-splk:combine_vars_simplify
Open

OpenTelemetryRumBuilder - Use lateinit vars instead of nullable/lazy.#1771
breedx-splk wants to merge 1 commit into
open-telemetry:mainfrom
breedx-splk:combine_vars_simplify

Conversation

@breedx-splk

Copy link
Copy Markdown
Contributor

This is a follow-up to this comment, which was part of #1767.

@breedx-splk breedx-splk requested a review from a team as a code owner May 26, 2026 17:48
@codecov

codecov Bot commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.80%. Comparing base (e6062e8) to head (f709824).

Files with missing lines Patch % Lines
...o/opentelemetry/android/OpenTelemetryRumBuilder.kt 66.66% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1771      +/-   ##
==========================================
- Coverage   62.97%   62.80%   -0.18%     
==========================================
  Files         157      157              
  Lines        3446     3441       -5     
  Branches      352      350       -2     
==========================================
- Hits         2170     2161       -9     
- Misses       1179     1181       +2     
- Partials       97       99       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

val cacheStorage: Lazy<CacheStorage> = lazy { cacheStorageOverride ?: CacheStorageImpl(context) }
val periodicTaskScheduler: Lazy<PeriodicTaskScheduler> =
lazy { periodicTaskSchedulerOverride ?: PeriodicTaskSchedulerImpl() }
cacheStorage = if (::cacheStorage.isInitialized) cacheStorage else CacheStorageImpl(context)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In my opinion, the usage of ::lateinitvar.isInitialized is a clear hint that said var must be nullable. Unless we're certain that those lateinit vars shall be set before they're referenced anywhere in the code, we should keep them nullable; otherwise, we'll be introducing a risk of getting a runtime exception, which defeats the purpose of lateinit var. Nullable vars are safer to use for these kinds of scenarios.

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