Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-11086

setVolume fires a Null pointer exception if called too soon

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.0.0, 2.1.0, 2.2.0, 2.3.0, 2.4.0, 2.5.0, 2.6.0, 2.7.0, 2.8.0, 2.9.0, 3.0.0, 3.1.0, 3.2.0, 3.3.0, 3.4.0, 2.9.1, 3.5.0
    • None
    • cordova-plugin-media

    Description

      On player creation, we can sometime observe:
      E/PluginManager( 5442): Uncaught exception from plugin
      E/PluginManager( 5442): java.lang.NullPointerException
      E/PluginManager( 5442): at org.apache.cordova.media.AudioPlayer.setVolume(AudioPlayer.java:441)
      E/PluginManager( 5442): at org.apache.cordova.media.AudioHandler.setVolume(AudioHandler.java:455)
      E/PluginManager( 5442): at org.apache.cordova.media.AudioHandler.execute(AudioHandler.java:143)
      E/PluginManager( 5442): at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
      E/PluginManager( 5442): at org.apache.cordova.PluginManager.exec(PluginManager.java:133)
      E/PluginManager( 5442): at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
      E/PluginManager( 5442): at org.apache.cordova.CordovaBridge.promptOnJsPrompt(CordovaBridge.java:135)
      E/PluginManager( 5442): at org.apache.cordova.engine.SystemWebChromeClient.onJsPrompt(SystemWebChromeClient.java:124)
      E/PluginManager( 5442): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:886)
      E/PluginManager( 5442): at android.os.Handler.dispatchMessage(Handler.java:99)
      E/PluginManager( 5442): at android.os.Looper.loop(Looper.java:137)
      E/PluginManager( 5442): at android.app.ActivityThread.main(ActivityThread.java:4921)
      E/PluginManager( 5442): at java.lang.reflect.Method.invokeNative(Native Method)
      E/PluginManager( 5442): at java.lang.reflect.Method.invoke(Method.java:511)
      E/PluginManager( 5442): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
      E/PluginManager( 5442): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
      E/PluginManager( 5442): at dalvik.system.NativeStart.main(Native Method)

      Attachments

        Activity

          githubbot ASF GitHub Bot added a comment -

          GitHub user fafaman opened a pull request:

          https://github.com/apache/cordova-plugin-media/pull/93

          Protect setVolume call in case Player object is referenced but not cr…

          Hi, this is a fix for https://issues.apache.org/jira/browse/CB-11086. thanks.

          You can merge this pull request into a Git repository by running:

          $ git pull https://github.com/fafaman/cordova-plugin-media CB-11086cordova-plugin-media

          Alternatively you can review and apply these changes as the patch at:

          https://github.com/apache/cordova-plugin-media/pull/93.patch

          To close this pull request, make a commit to your master/trunk branch
          with (at least) the following in the commit message:

          This closes #93


          commit 930fe187e0a2385ce9f693f8fc92b465c04e13ac
          Author: Fabrice Lebas <fabrice.lebas@gmail.com>
          Date: 2016-04-14T15:14:00Z

          Protect setVolume call in case Player object is referenced but not created yet


          githubbot ASF GitHub Bot added a comment - GitHub user fafaman opened a pull request: https://github.com/apache/cordova-plugin-media/pull/93 Protect setVolume call in case Player object is referenced but not cr… Hi, this is a fix for https://issues.apache.org/jira/browse/CB-11086 . thanks. You can merge this pull request into a Git repository by running: $ git pull https://github.com/fafaman/cordova-plugin-media CB-11086 cordova-plugin-media Alternatively you can review and apply these changes as the patch at: https://github.com/apache/cordova-plugin-media/pull/93.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #93 commit 930fe187e0a2385ce9f693f8fc92b465c04e13ac Author: Fabrice Lebas <fabrice.lebas@gmail.com> Date: 2016-04-14T15:14:00Z Protect setVolume call in case Player object is referenced but not created yet

          What does too soon mean - can you elaborate?

          nikhilkh Nikhil Khandelwal added a comment - What does too soon mean - can you elaborate?
          fafaman Fabrice Lebas added a comment -

          To be clear, this patch was done while looking after a problem of codrova app restarting when the phone is plugged or unplugged from a car audio stand. It seams that an event telling the app the audio system has changed makes the app restart. I first thought the app restart was due to that null pointer exception, but once fixed, the app still restarts... I decided to propose the patch (as well as CB-11085) so this work is not lost, and code cleaner for going forward. In my opinion, the real problem comes from the player creation logic: we should never have this.players.get(id) returning a non null while the player is null. There should be a mecanism in Android that indicates when the player is really ready.
          https://github.com/apache/cordova-plugin-media/pull/93#issuecomment-211529912

          fafaman Fabrice Lebas added a comment - To be clear, this patch was done while looking after a problem of codrova app restarting when the phone is plugged or unplugged from a car audio stand. It seams that an event telling the app the audio system has changed makes the app restart. I first thought the app restart was due to that null pointer exception, but once fixed, the app still restarts... I decided to propose the patch (as well as CB-11085 ) so this work is not lost, and code cleaner for going forward. In my opinion, the real problem comes from the player creation logic: we should never have this.players.get(id) returning a non null while the player is null. There should be a mecanism in Android that indicates when the player is really ready. https://github.com/apache/cordova-plugin-media/pull/93#issuecomment-211529912
          githubbot ASF GitHub Bot added a comment -

          GitHub user alsorokin opened a pull request:

          https://github.com/apache/cordova-plugin-media/pull/109

          CB-11086 (Android) Fixed a crash when setVolume() is called

              1. Platforms affected
                Android
              1. What does this PR do?
                This is a fix for https://issues.apache.org/jira/browse/CB-11086
                It fixes the crash by checking if player is null when trying to set player's volume.
              1. What testing has been done on this change?
                Tested on Android emulator 4.4, also checked that added test spec is green on iOS and Windows.
              1. Checklist

          You can merge this pull request into a Git repository by running:

          $ git pull https://github.com/alsorokin/cordova-plugin-media CB-11086

          Alternatively you can review and apply these changes as the patch at:

          https://github.com/apache/cordova-plugin-media/pull/109.patch

          To close this pull request, make a commit to your master/trunk branch
          with (at least) the following in the commit message:

          This closes #109


          commit 6c923c9b21a5417dc343aec901935be06e087e63
          Author: Alexander Sorokin <alexander.sorokin@akvelon.com>
          Date: 2016-08-23T14:18:31Z

          CB-11086 (Android) Fixed a crash when setVolume() is called on unitialized audio


          githubbot ASF GitHub Bot added a comment - GitHub user alsorokin opened a pull request: https://github.com/apache/cordova-plugin-media/pull/109 CB-11086 (Android) Fixed a crash when setVolume() is called Platforms affected Android What does this PR do? This is a fix for https://issues.apache.org/jira/browse/CB-11086 It fixes the crash by checking if player is null when trying to set player's volume. What testing has been done on this change? Tested on Android emulator 4.4, also checked that added test spec is green on iOS and Windows. Checklist [x] [ICLA] ( http://www.apache.org/licenses/icla.txt ) has been signed and submitted to secretary@apache.org. [x] [Reported an issue] ( http://cordova.apache.org/contribute/issues.html ) in the JIRA database [x] Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected. [x] Added automated test coverage as appropriate for this change. You can merge this pull request into a Git repository by running: $ git pull https://github.com/alsorokin/cordova-plugin-media CB-11086 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/cordova-plugin-media/pull/109.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #109 commit 6c923c9b21a5417dc343aec901935be06e087e63 Author: Alexander Sorokin <alexander.sorokin@akvelon.com> Date: 2016-08-23T14:18:31Z CB-11086 (Android) Fixed a crash when setVolume() is called on unitialized audio
          githubbot ASF GitHub Bot added a comment -

          Github user cordova-qa commented on the issue:

          https://github.com/apache/cordova-plugin-media/pull/109

          Cordova CI Build has completed successfully.

          *Commit* - [Link](https://github.com/apache/cordova-plugin-media/pull/109/commits/6c923c9b21a5417dc343aec901935be06e087e63)
          *Dashboard* - [Link](http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62/)

          Builder Name Console Output Test Report Device Logs
          :---: :---: :---: :---:
          [Windows 8.1 Store]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-store/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-store/console) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-store/testReport/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-store/artifact/)
          [Windows 10 Store]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-10-store/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-10-store/console) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-10-store/testReport/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-10-store/artifact/)
          [Windows 8.1 Phone]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-phone/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-phone/console) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-phone/testReport/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-phone/artifact/)
          [iOS]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=ios/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=ios/console) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=ios/testReport/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=ios/artifact/)
          [Android]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=android/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=android/console) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=android/testReport/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=android/artifact/)
          githubbot ASF GitHub Bot added a comment - Github user cordova-qa commented on the issue: https://github.com/apache/cordova-plugin-media/pull/109 Cordova CI Build has completed successfully. * Commit * - [Link] ( https://github.com/apache/cordova-plugin-media/pull/109/commits/6c923c9b21a5417dc343aec901935be06e087e63 ) * Dashboard * - [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62/ ) Builder Name Console Output Test Report Device Logs :---: :---: :---: :---: [Windows 8.1 Store] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-store/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-store/console ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-store/testReport/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-store/artifact/ ) [Windows 10 Store] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-10-store/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-10-store/console ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-10-store/testReport/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-10-store/artifact/ ) [Windows 8.1 Phone] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-phone/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-phone/console ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-phone/testReport/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=windows-8.1-phone/artifact/ ) [iOS] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=ios/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=ios/console ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=ios/testReport/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=ios/artifact/ ) [Android] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=android/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=android/console ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=android/testReport/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/62//PLATFORM=android/artifact/ )
          githubbot ASF GitHub Bot added a comment -

          Github user vladimir-kotikov commented on the issue:

          https://github.com/apache/cordova-plugin-media/pull/109

          LGTM

          githubbot ASF GitHub Bot added a comment - Github user vladimir-kotikov commented on the issue: https://github.com/apache/cordova-plugin-media/pull/109 LGTM
          githubbot ASF GitHub Bot added a comment -

          Github user cordova-qa commented on the issue:

          https://github.com/apache/cordova-plugin-media/pull/109

          Cordova CI Build has completed successfully.

          *Commit* - [Link](https://github.com/apache/cordova-plugin-media/pull/109/commits/67166333ebbbc1b8ac27e6825a7d73be30cea255)
          *Dashboard* - [Link](http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65/)

          Builder Name Console Output Test Report Device Logs
          :---: :---: :---: :---:
          [Windows 8.1 Store]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-store/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-store/console) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-store/testReport/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-store/artifact/)
          [Windows 10 Store]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-10-store/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-10-store/console) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-10-store/testReport/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-10-store/artifact/)
          [Windows 8.1 Phone]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-phone/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-phone/console) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-phone/testReport/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-phone/artifact/)
          [iOS]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=ios/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=ios/console) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=ios/testReport/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=ios/artifact/)
          [Android]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=android/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=android/console) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=android/testReport/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=android/artifact/)
          githubbot ASF GitHub Bot added a comment - Github user cordova-qa commented on the issue: https://github.com/apache/cordova-plugin-media/pull/109 Cordova CI Build has completed successfully. * Commit * - [Link] ( https://github.com/apache/cordova-plugin-media/pull/109/commits/67166333ebbbc1b8ac27e6825a7d73be30cea255 ) * Dashboard * - [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65/ ) Builder Name Console Output Test Report Device Logs :---: :---: :---: :---: [Windows 8.1 Store] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-store/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-store/console ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-store/testReport/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-store/artifact/ ) [Windows 10 Store] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-10-store/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-10-store/console ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-10-store/testReport/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-10-store/artifact/ ) [Windows 8.1 Phone] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-phone/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-phone/console ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-phone/testReport/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=windows-8.1-phone/artifact/ ) [iOS] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=ios/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=ios/console ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=ios/testReport/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=ios/artifact/ ) [Android] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=android/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=android/console ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=android/testReport/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-media-pr/65//PLATFORM=android/artifact/ )

          Commit 4d7aabb74a39bdfad0969915377e73106803cdf8 in cordova-plugin-media's branch refs/heads/master from alsorokin
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-media.git;h=4d7aabb ]

          CB-11086 (Android) Fixed a crash when setVolume() is called on unitialized audio
          This closes #93

          jira-bot ASF subversion and git services added a comment - Commit 4d7aabb74a39bdfad0969915377e73106803cdf8 in cordova-plugin-media's branch refs/heads/master from alsorokin [ https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-media.git;h=4d7aabb ] CB-11086 (Android) Fixed a crash when setVolume() is called on unitialized audio This closes #93
          githubbot ASF GitHub Bot added a comment -

          Github user alsorokin closed the pull request at:

          https://github.com/apache/cordova-plugin-media/pull/109

          githubbot ASF GitHub Bot added a comment - Github user alsorokin closed the pull request at: https://github.com/apache/cordova-plugin-media/pull/109
          githubbot ASF GitHub Bot added a comment -

          Github user asfgit closed the pull request at:

          https://github.com/apache/cordova-plugin-media/pull/93

          githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/cordova-plugin-media/pull/93

          People

            alsorokin Alexander Sorokin
            fafaman Fabrice Lebas
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 0.5h
                0.5h
                Remaining:
                Remaining Estimate - 0.5h
                0.5h
                Logged:
                Time Spent - Not Specified
                Not Specified