Skip to content

fix: guard against null in StreetView panorama change listeners#904

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

fix: guard against null in StreetView panorama change listeners#904
balazsbarany wants to merge 1 commit intogooglemaps: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.

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 29, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@balazsbarany balazsbarany force-pushed the fix/streetview-null-panorama-location-crash branch from fe2602c to 81a3328 Compare April 29, 2026 09:24
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.
@balazsbarany balazsbarany force-pushed the fix/streetview-null-panorama-location-crash branch from 81a3328 to 89b4b1f Compare April 29, 2026 09:30
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