Skip to content

fix(android): null-guard Player in Auth.onListen and getPlayerProfileImage - #249

Open
AbdullahGhanem wants to merge 1 commit into
Abedalkareem:developfrom
AbdullahGhanem:fix/null-player-onlisten
Open

fix(android): null-guard Player in Auth.onListen and getPlayerProfileImage#249
AbdullahGhanem wants to merge 1 commit into
Abedalkareem:developfrom
AbdullahGhanem:fix/null-player-onlisten

Conversation

@AbdullahGhanem

Copy link
Copy Markdown

Problem

PlayersClient.currentPlayer can complete successfully with a null Player (seen in production on a Xiaomi Mi 10 Pro, games_services 5.0.0 and reproducible against current develop). Auth.onListen — which backs GameAuth.player and therefore GameAuth.isSignedIn / GamesServices.isSignedIn — dereferences it immediately:

Fatal Exception: java.lang.NullPointerException
Attempt to invoke interface method 'java.lang.String com.google.android.gms.games.Player.getDisplayName()' on a null object reference
  at com.abedalkareem.games_services.Auth.onListen$lambda$0$0 (Auth.kt:147)
  at com.abedalkareem.games_services.Auth.onListen$lambda$0$1 (Auth.kt:145)
  at com.google.android.gms.tasks.zzm.run

Because this happens on the Android main thread inside a Task callback, a Dart-side try/catch around isSignedIn cannot catch it — the whole app crashes on what should be a harmless "are we signed in?" query.

Fix

Apply the same guard signIn() already has (added in 5.3.0) to the two remaining currentPlayer success listeners:

  • onListen: emit FailedToAuthenticate through the event sink (Dart side then resolves isSignedIn to false).
  • getPlayerProfileImage: return FailedToGetPlayerProfileImage.

9 lines, Android only, no API change.

…Image

PlayersClient.currentPlayer can complete successfully with a null Player.
onListen (used by GameAuth.player / isSignedIn) dereferenced it directly,
crashing the app with a NullPointerException on the main thread. Report
FailedToAuthenticate through the event sink instead, mirroring the guard
already present in signIn().
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.

1 participant