DataDog / dd-sdk-android

Datadog SDK for Android (Compatible with Kotlin and Java)
Apache License 2.0
146 stars 59 forks source link

RUM-3992 Prevent crash in JankStats listener #1981

Closed xgouchet closed 4 months ago

xgouchet commented 4 months ago

What does this PR do?

Fixes #1976

In Android N (until Android P included), the internal View. findFrameMetricsObserver() method did not check the nullability of the mFrameMetricsObservers field, leading to possible NPE when trying to remove a listener that wasn't yet added.

Motivation

Some customer have seen a crash with an NPE thrown from the Android View when removing the FrameMetricsListener via the JankStats library. Even though all versions of the official Android View are written in a way that NPE should never happen, those crash still occurred.

codecov-commenter commented 4 months ago

Codecov Report

Merging #1981 (eca3a98) into develop (768fa8a) will decrease coverage by 0.10%. Report is 1 commits behind head on develop. The diff coverage is 100.00%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #1981 +/- ## =========================================== - Coverage 83.71% 83.61% -0.10% =========================================== Files 487 487 Lines 17737 17695 -42 Branches 2663 2656 -7 =========================================== - Hits 14848 14795 -53 Misses 2170 2170 - Partials 719 730 +11 ``` | [Files](https://app.codecov.io/gh/DataDog/dd-sdk-android/pull/1981?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog) | Coverage Δ | | |---|---|---| | [...ernal/vitals/JankStatsActivityLifecycleListener.kt](https://app.codecov.io/gh/DataDog/dd-sdk-android/pull/1981?src=pr&el=tree&filepath=features%2Fdd-sdk-android-rum%2Fsrc%2Fmain%2Fkotlin%2Fcom%2Fdatadog%2Fandroid%2Frum%2Finternal%2Fvitals%2FJankStatsActivityLifecycleListener.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog#diff-ZmVhdHVyZXMvZGQtc2RrLWFuZHJvaWQtcnVtL3NyYy9tYWluL2tvdGxpbi9jb20vZGF0YWRvZy9hbmRyb2lkL3J1bS9pbnRlcm5hbC92aXRhbHMvSmFua1N0YXRzQWN0aXZpdHlMaWZlY3ljbGVMaXN0ZW5lci5rdA==) | `69.17% <100.00%> (+0.75%)` | :arrow_up: | ... and [24 files with indirect coverage changes](https://app.codecov.io/gh/DataDog/dd-sdk-android/pull/1981/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog)