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 ZoneRules.isFixedOffset #149

Closed
MarioNoll opened this issue Oct 1, 2021 · 13 comments · Fixed by #150
Closed

ArrayIndexOutOfBoundsException ZoneRules.isFixedOffset #149

MarioNoll opened this issue Oct 1, 2021 · 13 comments · Fixed by #150
Labels
bug Something isn't working

Comments

@MarioNoll
Copy link

After updating to kotlinx-datetime:0.3.0 I am seeing crashes on Android with the following stacktrace:

java.lang.ArrayIndexOutOfBoundsException: length=0; index=-1
at j$.time.zone.ZoneRules.isFixedOffset
at kotlinx.datetime.TimeZone$Companion.ofZone$kotlinx_datetime(SourceFile:47)
at kotlinx.datetime.TimeZone$Companion.currentSystemDefault(SourceFile:34)

I am not totally sure where to report this, the crash is introduced due to 0.3.0 making calls to ZoneRules.isFixedOffset.
Though by looking at the source code of java.time.zone.ZoneRules here, I can't see how an ArrayIndexOutOfBoundsException can happen.

I have coreLibraryDesugaring enabled, using com.android.tools:desugar_jdk_libs:1.1.5

@dkhalanskyjb dkhalanskyjb added the bug Something isn't working label Oct 1, 2021
@dkhalanskyjb
Copy link
Collaborator

Could you please try calling java.time.ZoneId.systemDefault() and tell us what time zone is returned as a result?

@MarioNoll
Copy link
Author

MarioNoll commented Oct 1, 2021

Currently I can see the two following timezones in Sentry, for users running into this crash:

Africa/Cairo
America/Costa_Rica

I quickly changed my timezone to America/Costa_Rica and was able to reproduce the crash. My local stacktrace provides some more details:

Caused by java.lang.ArrayIndexOutOfBoundsException: length=0; index=-1
at j$.time.zone.ZoneRules.previousTransition(ZoneRules.java:1108)
at j$.time.zone.ZoneRules.isFixedOffset(ZoneRules.java:514)
at kotlinx.datetime.TimeZone$Companion.ofZone$kotlinx_datetime(TimeZoneJvm.kt:47)
at kotlinx.datetime.TimeZone$Companion.currentSystemDefault(TimeZoneJvm.kt:34)

@dkhalanskyjb
Copy link
Collaborator

Are you able to reproduce this in the emulator? If so, could you please provide a reproducing project? I wasn't able to make the app crash in the emulator. Or is a device needed for the crash to occur?

Also, can you confirm that the line

java.time.ZoneId.of("America/Costa_Rica").rules.isFixedOffset

also crashes your app?

@MarioNoll
Copy link
Author

MarioNoll commented Oct 4, 2021

Are you able to reproduce this in the emulator? If so, could you please provide a reproducing project? I wasn't able to make the app crash in the emulator. Or is a device needed for the crash to occur?

It crashes in the emulator as well as on the device, here is a small reproducer project. Basically I just copied your line of code into here and enabled coreLibraryDeSugaring here

Also, can you confirm that the line...

Yes, I can confirm that the line of code you posted is enough to produce the above mentioned crash.

@dkhalanskyjb
Copy link
Collaborator

Thanks! I managed to reproduce it on an emulator with the API level 24. With the API level 30, everything is fine.

I suppose it's really up to us to work around this to support older versions, as Google seems to have fixed this already in the newer SDKs.

@PaulWoitaschek
Copy link

PaulWoitaschek commented Oct 4, 2021

Well this $j calls come from the desugar logic right? In addition to being worked around here this should be fixed upstream as well?
That function doesn't exist in api 24 so it's a pure backport:
https://developer.android.com/reference/java/time/zone/ZoneRules#isFixedOffset()

@looploooop Didn't we have this issue on Android 30 as well?

I think here is where the crash is happening:
https://github.com/google/desugar_jdk_libs/blob/d1ca594532d3443822cc10c7a0856316e16f3e34/jdk11/src/java.base/share/classes/java/time/zone/ZoneRules.java#L1107

@MarioNoll
Copy link
Author

Didn't we have this issue on Android 30 as well?

Yes, looking at Sentry our users experienced this crash on API level versions 27-30

@dkhalanskyjb
Copy link
Collaborator

I've already prepared a workaround that should cover all the versions. Regarding reporting this to Google: were you able to reproduce this issue on API level 30?

@MarioNoll
Copy link
Author

Yes, crashes on my Pixel 5 with API level 30 as well as in the Emulator with API level 31.

@dkhalanskyjb
Copy link
Collaborator

This is odd. Running your reproducing project in Android Studio 2021.1.1 on Linux, I get a crash on the Nexus 4 API 24 emulator, but no crash on Pixel 2 API 30, Pixel 5 API 31, or Pixel 5 API 30.

@MarioNoll
Copy link
Author

Weird I just checked again, this crashes in an emulator Pixel 5 API 31, as well with Android Studio 2021.1.1 on Linux withopenjdk version "11.0.12" 2021-07-20

@mustafaozhan
Copy link

Just confirming that, I start to have this crash starting with 0.3.0. It was not happening before.

@boiler23
Copy link

Hi guys, could please give some estimate for the next release which fixes this? iosSimulatorArm64 is important to us, but we cannot upgrade to 0.3.0 until this issue is fixed - it generates a lot of crashes in Android production. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants