Skip to content

fix: guard against null in StreetView panorama change listeners - #970

Open
balazsbarany wants to merge 1 commit into
googlemaps:mainfrom
balazsbarany:fix/streetview-null-panorama-location-crash
Open

fix: guard against null in StreetView panorama change listeners#970
balazsbarany wants to merge 1 commit into
googlemaps:mainfrom
balazsbarany:fix/streetview-null-panorama-location-crash

Conversation

@balazsbarany

Copy link
Copy Markdown

Description

The OnStreetViewPanoramaChangeListener and OnStreetViewPanoramaCameraChangeListener Java interfaces in play-services-maps do not annotate their callback parameters as @NonNull. The GMS dynamite module (policy_maps_core_dynamite) can deliver null to these listeners on certain devices and Play Services versions.

In StreetViewPanoramaPropertiesNode.onAttached(), both lambdas assigned the callback value directly to non-nullable Kotlin state fields (rawLocation and rawPanoramaCamera). The Kotlin compiler inserts an implicit null-check intrinsic at lambda entry — before the assignment — which throws a NullPointerException when null arrives, crashing the app.

Crash trace

Fatal Exception: com.google.maps.api.android.lib6.common.apiexception.f: NullPointerException:
  Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
    at com.google.maps.android.compose.streetview.StreetViewPanoramaPropertiesNode.onAttached$lambda$3

Lambda index 3 in onAttached() is the setOnStreetViewPanoramaChangeListener callback. The getClass() call is the Kotlin-generated null check, not application code.

Changes

Guard both listener assignments with a null-safe let block in StreetViewPanoramaUpdater.kt:

// before
panorama.setOnStreetViewPanoramaChangeListener {
    cameraPositionState.rawLocation = it
}

// after
panorama.setOnStreetViewPanoramaChangeListener {
    it?.let { cameraPositionState.rawLocation = it }
}

The same pattern is applied to setOnStreetViewPanoramaCameraChangeListener for consistency, as StreetViewPanoramaCamera is also non-nullable in rawPanoramaCamera but the Java interface carries no @NonNull guarantee.

Testing

The fix is purely defensive against a null delivery from the GMS layer, which cannot be injected in an instrumented test. The existing StreetViewTests continue to exercise the normal flow unchanged.


Re-submission of #904, which was closed when the original fork was deleted. Same commit (89b4b1f, author unchanged, Google CLA signed as an individual), cherry-picked onto current main — the diff is identical.

The OnStreetViewPanoramaChangeListener and
OnStreetViewPanoramaCameraChangeListener Java interfaces do not
annotate their parameters as @nonnull. The GMS dynamite module
(policy_maps_core_dynamite) can deliver null to these listeners on
certain devices and Play Services versions. The Kotlin compiler inserts
an implicit null-check intrinsic at lambda entry which throws a
NullPointerException before the assignment is reached, crashing the app.

Fixes the crash by guarding both assignments with a null-safe let block.

@kikoso kikoso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

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.

3 participants