ACRA / acra

Application Crash Reports for Android

Home Page:https://www.acra.ch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ACRA initialization : getting ClassCastException on application update

razmo51 opened this issue · comments

Describe the bug
When I install my application with ACRA (5.11.0) on a device that had a previous version of my application with a previous version of ACRA (5.9.7), I get a crash on ACRA initialization.

The error is:

            E  ACRA caught a ClassCastException for com.*******
                            java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
                                at android.app.SharedPreferencesImpl.getLong(SharedPreferencesImpl.java:329)
                                at org.acra.startup.LimiterStartupProcessor.processReports(SourceFile:49)
                                at v4.a.run(SourceFile:131)
                                at java.lang.Thread.run(Thread.java:1012)

I think it was caused by a change made a month ago on the LimiterStartupProcessor in this commit:

1bf91f3#diff-0ef0f1b414770d23f2d21a88657bb270f0bc08ec80b25dd1a6caf1d9546fa72a

which replaced the prefs.getInt(...).toLong() by prefs.getLong(...), the previous value (from older ACRA version) was indeed an java.lang.Integer and cannot be casted to a java.lang.Long

The workaround I found was to change the sharedPreferencesName on the Core config so the previous value is not used.

(I'm sorry I didn't have time to enable ACRA.DEBUG. I worked around the error as my work load is high at the moment, I needed to find a quick solution)

Expected behavior
ACRA initialization without crash

Version

  • Android: 12
  • ACRA: 5.11.0

Just a note: this appeared to pop up again though we have released acra 5.11.1 in the version of the app that we saw it in 🤔

Current untested thought (from the comment in our related issue):

Current possibility: is the code in c193e35 catching the Kotlin ClassCastException, and does this also handle java.lang.ClassCastException

@mikehardy kotlin ClassCastException is a typealias for java.lang, so that's not it. Do you have a stacktrace?

I had a look at your linked issue, and it seems to be the other way around (long cast to integer) compared to this issue (int cast to long)