Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE in MediaControllerImplLegacy#connectToSession() #59

Merged

Conversation

h6ah4i
Copy link
Contributor

@h6ah4i h6ah4i commented Mar 26, 2022

This pull request fixes a NullPointerException occurs inside of the MediaControllerImplLegacy#connectToSession().

2022-03-27 00:28:23.683 31182-31211/? E/AndroidRuntime: FATAL EXCEPTION: MCwMSCTest
    Process: androidx.media3.test.session, PID: 31182
    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.support.v4.media.session.MediaControllerCompat.isSessionReady()' on a null object reference
        at androidx.media3.session.MediaControllerImplLegacy.lambda$connectToSession$2$androidx-media3-session-MediaControllerImplLegacy(MediaControllerImplLegacy.java:1274)
        at androidx.media3.session.MediaControllerImplLegacy$$ExternalSyntheticLambda14.run(Unknown Source:2)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.os.HandlerThread.run(HandlerThread.java:67)

Where the NPE occurs

Scenario

  1. Create a MediaController instance
    • 馃憠 MediaControllerImplLegacy posts a callback which is executed on the main thread
  2. Call MediaController#release() immediately on the main thread
    • 馃憠 MediaControllerImplLegacy sets controllerCompat = null
  3. The callback registered at Step 2 is invoked
    • 馃憠 controllerCompat.isSessionReady() is called 馃挜

Current implementation of the release() method have a bug;
it does not clear pending messages/callbacks queued to the
applicationHandler.
This fixes the NPE ocuured in the MediaControllerImplLegacy#connectToSession()
right after MediaController#release() is called.
@h6ah4i h6ah4i changed the base branch from release to main March 27, 2022 12:43
@icbaker icbaker merged commit 85c0975 into androidx:main Apr 26, 2022
@androidx androidx locked and limited conversation to collaborators Mar 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants