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

ArrayIndexOutOfBoundsException #5240

Closed
Khang-NT opened this issue Dec 11, 2018 · 11 comments
Closed

ArrayIndexOutOfBoundsException #5240

Khang-NT opened this issue Dec 11, 2018 · 11 comments
Assignees

Comments

@Khang-NT
Copy link
Contributor

Issue description

I see some crash reports:

Fatal Exception: java.lang.ArrayIndexOutOfBoundsException: length=2; index=-1
       at com.google.android.exoplayer2.source.ConcatenatingMediaSource$ConcatenatedTimeline.getFirstWindowIndexByChildIndex(SourceFile:922)
       at com.google.android.exoplayer2.source.AbstractConcatenatedTimeline.getPeriodByUid(SourceFile:207)
       at com.google.android.exoplayer2.ExoPlayerImpl.getCurrentWindowIndex(SourceFile:460)
       at com.google.android.exoplayer2.analytics.AnalyticsCollector.generateEventTime(SourceFile:632)
       at com.google.android.exoplayer2.analytics.AnalyticsCollector.generatePlayingMediaPeriodEventTime(SourceFile:650)
       at com.google.android.exoplayer2.analytics.AnalyticsCollector.onTimelineChanged(SourceFile:442)
       at com.google.android.exoplayer2.ExoPlayerImpl$PlaybackInfoUpdate.notifyListeners(SourceFile:771)
       at com.google.android.exoplayer2.ExoPlayerImpl.updatePlaybackInfo(SourceFile:708)
       at com.google.android.exoplayer2.ExoPlayerImpl.handlePlaybackInfo(SourceFile:639)
       at com.google.android.exoplayer2.ExoPlayerImpl.handleEvent(SourceFile:584)
       at com.google.android.exoplayer2.ExoPlayerImpl$1.handleMessage(SourceFile:125)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:193)
       at android.os.HandlerThread.run(HandlerThread.java:65)

(index always = -1)

Do you have any idea why it happen?
It maybe something wrong with my implementation, but I'm pretty sure that I access ExoPlayer instance and update ConcatenatingMediaSource in single thread. The stack trace is quite complicated to me to investigate, so please take a look.

Reproduction steps

Can't.

Link to test content

Not available.

Version of ExoPlayer being used

2.9.2

Device(s) and version(s) of Android being used

Variety devices.
Variety os versions.

@tonihei tonihei self-assigned this Dec 11, 2018
@tonihei
Copy link
Collaborator

tonihei commented Dec 11, 2018

Can't see any issue with the code and it looks almost impossible that this should happen.

That's what I concluded from the stack trace:

  • ConcatenatedTimeline.getFirstWindowIndexByChildIndex is called with the invalid index -1
  • AbstractConcatenatedTimeline.getPeriodByUid gets the index from a call to ConcatenatedTimeline.getChildIndexByChildUid which may return -1 but only if the uid is not part of the timeline.
  • This means ConcatenatedTimeline.getPeriodByUid must have been called with a uid which is not part of the timeline.
  • ExoPlayerImpl calls playbackInfo.timeline.getPeriodByUid(playbackInfo.periodId.periodUid,...) which suggests that the periodId.periodUid in a PlaybackInfo object is not part of the timeline in the same PlaybackInfo object.
  • All internal code paths updating either the period uid or the timeline in the immutable PlaybackInfo object ensure that this can't happen (unless timeline is empty which doesn't apply here).

There must obviously be some flaw in my reasoning here, otherwise you wouldn't see the crash. :)

As you already mentioned, it could be that something writes information in parallel. Are you using the main thread for all player access or a background thread? And on which thread do you create the player?

Also, do you have any other information about the context of the crash? Which player interactions came before the crash for example?

@sneltyn
Copy link

sneltyn commented Dec 15, 2018

@tonihei, i also have this problem :(

Stack trace:

java.lang.ArrayIndexOutOfBoundsException: length=0; index=-1
    at com.google.android.exoplayer2.source.ConcatenatingMediaSource$ConcatenatedTimeline.e
    at com.google.android.exoplayer2.source.AbstractConcatenatedTimeline.getPeriodByUid
    at com.google.android.exoplayer2.ExoPlayerImpl.getCurrentWindowIndex
    at com.google.android.exoplayer2.analytics.AnalyticsCollector.generateEventTime
    at com.google.android.exoplayer2.analytics.AnalyticsCollector.generatePlayingMediaPeriodEventTime
    at com.google.android.exoplayer2.analytics.AnalyticsCollector.onTimelineChanged
    at com.google.android.exoplayer2.ExoPlayerImpl$PlaybackInfoUpdate.notifyListeners
    at com.google.android.exoplayer2.ExoPlayerImpl.updatePlaybackInfo
    at com.google.android.exoplayer2.ExoPlayerImpl.handlePlaybackInfo
    at com.google.android.exoplayer2.ExoPlayerImpl.a
    at com.google.android.exoplayer2.ExoPlayerImpl$1.handleMessage
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6121)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:892)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)

ExoPlayer: 2.9.0

All methods of ConcatenatingMediaSource are executed in the main thread. I can not reproduce the problem appears randomly.

@juechemparathy
Copy link

@tonihei - We also started noticing this on upgrade form 2.7.3 -> 2.9.0
Intermittent but seen happening with Live/dash multiple period scenarios.
Sample stream:
https://content-duseqa1.downlynk.com/channel/29e9c85c070f413fb71a3b2a39eed208.mpd?ad=dashad

11-22 14:33:27.683 5447-7882/com.yahoo.mobile.client.android.example.yvideosdkdemo E/ExoPlayerImplInternal:Handler-561: UNCAUGHT EXCEPTION
    java.lang.ArrayIndexOutOfBoundsException: length=1; index=-1
        at com.google.android.exoplayer2.source.ConcatenatingMediaSource$ConcatenatedTimeline.getFirstWindowIndexByChildIndex(ConcatenatingMediaSource.java:880)
        at com.google.android.exoplayer2.source.AbstractConcatenatedTimeline.getPeriod(AbstractConcatenatedTimeline.java:217)
        at com.google.android.exoplayer2.source.ForwardingTimeline.getPeriod(ForwardingTimeline.java:72)
        at com.google.android.exoplayer2.Timeline.getPeriodByUid(Timeline.java:757)
        at com.google.android.exoplayer2.ExoPlayerImpl.getCurrentWindowIndex(ExoPlayerImpl.java:492)
        at com.google.android.exoplayer2.ExoPlayerImpl.createMessage(ExoPlayerImpl.java:444)
        at com.google.android.exoplayer2.source.ConcatenatingMediaSource.scheduleListenerNotification(ConcatenatingMediaSource.java:611)
        at com.google.android.exoplayer2.source.ConcatenatingMediaSource.updateMediaSourceInternal(ConcatenatingMediaSource.java:702)
        at com.google.android.exoplayer2.source.ConcatenatingMediaSource.onChildSourceInfoRefreshed(ConcatenatingMediaSource.java:525)
        at com.google.android.exoplayer2.source.ConcatenatingMediaSource.onChildSourceInfoRefreshed(ConcatenatingMediaSource.java:47)
        at com.google.android.exoplayer2.source.CompositeMediaSource.lambda$prepareChildSource$0(CompositeMediaSource.java:104)
        at com.google.android.exoplayer2.source.-$$Lambda$CompositeMediaSource$ahAPO18YbnzL6kKRAWdp4FR_Vco.onSourceInfoRefreshed(Unknown Source:4)
        at com.verizondigitalmedia.mobile.client.android.player.extensions.MediaItemMediaSource.maybeNotifyTimeline(MediaItemMediaSource.java:102)
        at com.verizondigitalmedia.mobile.client.android.player.extensions.MediaItemMediaSource$1.onSourceInfoRefreshed(MediaItemMediaSource.java:47)
        at com.google.android.exoplayer2.source.BaseMediaSource.refreshSourceInfo(BaseMediaSource.java:79)
        at com.google.android.exoplayer2.source.dash.DashMediaSource.processManifest(DashMediaSource.java:980)
        at com.google.android.exoplayer2.source.dash.DashMediaSource.lambda$new$0(DashMediaSource.java:593)
        at com.google.android.exoplayer2.source.dash.-$$Lambda$DashMediaSource$e1nzB-O4m3YSG1BkxQDKPaNvDa8.run(Unknown Source:2)
        at android.os.Handler.handleCallback(Handler.java:789)```

@tonihei
Copy link
Collaborator

tonihei commented Dec 17, 2018

@sneltyn This is unrelated and it looks like a known bug we had in 2.8. This should already be fixed.

@juechemparathy This may also be unrelated. It seems that you are using your own MediaSource. Can you check what kind of Timeline this media source is returning and if the uid value of the periods + the value returned by getIndexOfPeriod fit together?

@sneltyn
Copy link

sneltyn commented Dec 24, 2018

@tonihei, thank! Perhaps you are right and the problem that is fixed above. If it appears then I will inform you.

@sneltyn
Copy link

sneltyn commented Dec 24, 2018

@tonihei, I caught the same problem as in this ticket.

Stack trace:

java.lang.ArrayIndexOutOfBoundsException: length=2; index=-1
        at com.google.android.exoplayer2.source.ConcatenatingMediaSource$ConcatenatedTimeline.getFirstWindowIndexByChildIndex(ConcatenatingMediaSource.java:922)
        at com.google.android.exoplayer2.source.AbstractConcatenatedTimeline.getPeriodByUid(AbstractConcatenatedTimeline.java:207)
        at com.google.android.exoplayer2.ExoPlayerImpl.getCurrentWindowIndex(ExoPlayerImpl.java:460)
        at com.google.android.exoplayer2.analytics.AnalyticsCollector.generateEventTime(AnalyticsCollector.java:632)
        at com.google.android.exoplayer2.analytics.AnalyticsCollector.generatePlayingMediaPeriodEventTime(AnalyticsCollector.java:650)
        at com.google.android.exoplayer2.analytics.AnalyticsCollector.onTimelineChanged(AnalyticsCollector.java:442)
        at com.google.android.exoplayer2.ExoPlayerImpl$PlaybackInfoUpdate.notifyListeners(ExoPlayerImpl.java:771)
        at com.google.android.exoplayer2.ExoPlayerImpl.updatePlaybackInfo(ExoPlayerImpl.java:708)
        at com.google.android.exoplayer2.ExoPlayerImpl.handlePlaybackInfo(ExoPlayerImpl.java:639)
        at com.google.android.exoplayer2.ExoPlayerImpl.handleEvent(ExoPlayerImpl.java:584)
        at com.google.android.exoplayer2.ExoPlayerImpl$1.handleMessage(ExoPlayerImpl.java:125)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6696)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)

ExoPlayer: 2.9.2

I can make a demo in which this problem manifests itself.

@tonihei
Copy link
Collaborator

tonihei commented Dec 25, 2018

I can make a demo in which this problem manifests itself

That would be great! If you have a demo to reproduce the problem, we can probably find out what's wrong.

@tonihei
Copy link
Collaborator

tonihei commented Dec 25, 2018

Just found a potential problem: It looks like we are accessing the player from the wrong thread internally when creating the message to notify the listeners about updates in the playlist. Even though we should fix this, I'm not sure whether this can cause the stack traces posted above.

@sneltyn
Copy link

sneltyn commented Dec 25, 2018

@tonihei, ok, I'll post a demo soon.

@ojw28 ojw28 added the bug label Dec 29, 2018
@ojw28
Copy link
Contributor

ojw28 commented Dec 29, 2018

Marking as a bug for tracking the issue Toni mentions above.

ojw28 pushed a commit that referenced this issue Jan 8, 2019
ExoPlayer methods must not be called from any thread besides the specified
app thread. Therefore we shouldn't use them here. Using a regular Handler
instead is fully equivalent.

Issue:#5240
PiperOrigin-RevId: 227650489
@ojw28 ojw28 removed the bug label Jan 10, 2019
ojw28 pushed a commit that referenced this issue Jan 15, 2019
ExoPlayer methods must not be called from any thread besides the specified
app thread. Therefore we shouldn't use them here. Using a regular Handler
instead is fully equivalent.

Issue:#5240
PiperOrigin-RevId: 227650489
@tonihei
Copy link
Collaborator

tonihei commented Jan 18, 2019

Closing as no further evidence of a problem was reported and we have no actionable info to do something. Please re-open if you can provide further information that would help us to identify if and where the problem actually is.

@tonihei tonihei closed this as completed Jan 18, 2019
@google google locked and limited conversation to collaborators Aug 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants