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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NullPointerException in setEnterPictureInPictureOnLeave for unsupported Android versions #4362

Merged

Conversation

bae-unidev
Copy link
Contributor

Summary

A NullPointerException was occurring when calling setEnterPictureInPictureOnLeave on devices running Android versions below Build.VERSION_CODES.O. The issue was caused by the fact that PictureInPictureUtil#applyAutoEnterEnabled was being called even for unsupported Android versions, where pictureInPictureParamsBuilder might not be initialized, leading to a null parameter passed to the Kotlin function applyAutoEnterEnabled.

public ReactExoplayerView(ThemedReactContext context, ReactExoplayerConfig config) {
  // ...
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && pictureInPictureParamsBuilder == null) {
       this.pictureInPictureParamsBuilder = new PictureInPictureParams.Builder();
  }
  // ...
Fatal Exception: com.facebook.react.bridge.JSApplicationIllegalArgumentException
Error while updating property 'enterPictureInPictureOnLeave' of a view managed by: RCTVideo
          Caused by java.lang.NullPointerException: Parameter specified as non-null is null: method com.brentvatne.exoplayer.PictureInPictureUtil.applyAutoEnterEnabled, parameter pipParamsBuilder
       at com.brentvatne.exoplayer.PictureInPictureUtil.applyAutoEnterEnabled(PictureInPictureUtil.kt)
       at com.brentvatne.exoplayer.ReactExoplayerView.setEnterPictureInPictureOnLeave(ReactExoplayerView.java:2156)
       at com.brentvatne.exoplayer.ReactExoplayerViewManager.setEnterPictureInPictureOnLeave(ReactExoplayerViewManager.kt:169)

@YangJonghun
Copy link
Collaborator

YangJonghun commented Jan 8, 2025

@bae-unidev
Thanks for contribute:)
It was my mistake within #3385

How about modifying applyAutoEntryEnabled like below? I wanted to reduce complexity of the ReactExoplayerView by branching from PictureInPictureUtil if possible.

-    fun applyAutoEnterEnabled(context: ThemedReactContext, pipParamsBuilder: PictureInPictureParams.Builder, autoEnterEnabled: Boolean) {
-        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return
+    fun applyAutoEnterEnabled(context: ThemedReactContext, pipParamsBuilder: PictureInPictureParams.Builder?, autoEnterEnabled: Boolean) {
+        if (pipParamsBuilder == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return

It also seems that NullPointerException can be thrown by other PictureInPictureUtil.apply* methods.

@bae-unidev bae-unidev force-pushed the fix-npe-android-o-pip branch from 384a060 to a7b14e2 Compare January 8, 2025 07:12
@bae-unidev
Copy link
Contributor Author

@YangJonghun

I completely agree with your approach to reduce the complexity of ReactExoplayerView by moving branching logic into PictureInPictureUtil. I’ve updated applyAutoEnterEnabled and other similar methods in PictureInPictureUtil to handle null checks directly and ensure NPE safety.

Copy link
Collaborator

@YangJonghun YangJonghun left a comment

Choose a reason for hiding this comment

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

LGTM😁

Copy link
Member

@KrzysztofMoch KrzysztofMoch left a comment

Choose a reason for hiding this comment

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

Thanks!

@KrzysztofMoch KrzysztofMoch merged commit 3924b5e into TheWidlarzGroup:master Jan 10, 2025
3 checks passed
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.

4 participants