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

java.lang.InstantiationError crash in prod during posthog init #135

Closed
alekseyrozh opened this issue May 27, 2024 · 9 comments · Fixed by #140
Closed

java.lang.InstantiationError crash in prod during posthog init #135

alekseyrozh opened this issue May 27, 2024 · 9 comments · Fixed by #140
Labels
bug Something isn't working question Further information is requested

Comments

@alekseyrozh
Copy link

alekseyrozh commented May 27, 2024

Version

3.1.1

Steps to Reproduce

This is firebase carshlytics report from a production app. It occasionally fails on startup due to the posthog crash. For a certain user it crashed 4 times in a row on this error

Android 10
Model:A5 2020
Brand:Oppo

Expected Result

Not crash

Actual Result

  Fatal Exception: java.lang.InstantiationError: F8.c
   at com.posthog.PostHog.setup(PostHog.java:66)
   at com.posthog.PostHog$Companion.setup(PostHog.java:648)
   at com.posthog.android.PostHogAndroid$Companion.setup(PostHogAndroid.java:42)
   at com.evelize.teleprompter.TeleprompterApplication.initPostHog(TeleprompterApplication.kt:128)
   at com.evelize.teleprompter.TeleprompterApplication.onCreate(TeleprompterApplication.kt:57)
   at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1199)
   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6913)
   at android.app.ActivityThread.access$1600(ActivityThread.java:240)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2067)
   at android.os.Handler.dispatchMessage(Handler.java:107)
   at android.os.Looper.loop(Looper.java:241)
   at android.app.ActivityThread.main(ActivityThread.java:7888)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:512)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:998)

Stack trace points here, that leaves me fairly confused

Screenshot 2024-05-27 at 14 39 40

The way I call it from my code is:
Screenshot 2024-05-27 at 14 40 55

@alekseyrozh alekseyrozh added the bug Something isn't working label May 27, 2024
@marandaneto
Copy link
Member

@alekseyrozh Yeah that is strange, do you minify your app?
the name F8.c seems to be something minified and minification affects line number so it's hard to tell where exactly it is.
There were a bunch of bug fixes tho since you are using 3.1.1, mind upgrading and checking out if this still happens in the newer version?

@marandaneto marandaneto added the question Further information is requested label May 27, 2024
@alekseyrozh
Copy link
Author

@marandaneto I do minify yes, when libs require exclusions there's usually a proguard config given to exclude certain classes. Like this one: https://github.com/square/retrofit/blob/trunk/retrofit/src/main/resources/META-INF/proguard/retrofit2.pro If posthog relies on some class names being preserved, could you please provide relevant proguard config.

The error itself doesn't look like its cause by minification though. I will upgrade the version and update this thread in some time, in the meanwhile could you please do the analysis of this error on your side 🙏

@marandaneto
Copy link
Member

@alekseyrozh I did check and nothing was obvious.

Gson uses reflection but we do have the shipped proguard rules.

So minify isn't a problem afaik, otherwise it'd be crashing for everyone.

We also didn't get any reports from anyone else related to InstantiationError.

Since you have the proguard mapping file so symbolicate and check the real names and line numbers.
Could you symbolicate the following lines:

Fatal Exception: java.lang.InstantiationError: F8.c
at com.posthog.PostHog.setup(PostHog.java:66)
at com.posthog.PostHog$Companion.setup(PostHog.java:648)
at com.posthog.android.PostHogAndroid$Companion.setup(PostHogAndroid.java:42)

So we know what exactly F8.c is and the line numbers? you can use https://www.guardsquare.com/manual/tools/retrace for that

@marandaneto
Copy link
Member

@alekseyrozh What is the AGP version? what is the Gradle version? do you have the R8 full mode enabled?

@alekseyrozh
Copy link
Author

@marandaneto from what I read R8 full mode is enabled by default: https://developer.android.com/build/shrink-code#full-mode.

My setup if quite default:

          isMinifyEnabled = true
          isShrinkResources = true
          proguardFiles(
              getDefaultProguardFile("proguard-android-optimize.txt"),
              "proguard-rules.pro"
          )

and here is the list of plugin versions:

plugins {
    id("com.android.application") version "8.3.2" apply false
    id("com.android.library") version "8.3.2" apply false
    id("org.jetbrains.kotlin.android") version "1.9.23" apply false
    id("org.jetbrains.kotlin.plugin.serialization") version "1.9.23" apply false
    id("com.google.devtools.ksp") version "1.9.23-1.0.20" apply false
    id("com.google.gms.google-services") version "4.4.0" apply false
    id("com.google.firebase.crashlytics") version "2.9.9" apply false
}

@marandaneto
Copy link
Member

@alekseyrozh full mode is enabled after AGP >= 8, and you are using 8.3.2 so indeed it is.
Please take a look at this comment, since I cannot reproduce this locally on my own, maybe with extra info, I can try again, thanks.

@alekseyrozh
Copy link
Author

@marandaneto I tried retracing as you suggested, however in the output I saw the exact same stacktrace as I attached to this issue. Which made me realise that all other lines of code are actually using full classnames and correct line numbers. So the stack trace is actually referring to the original source code, just not the error message itself. I'm not very familiar with this procedure, so I might have missed smth. Please let me know if so

Screenshot 2024-06-08 at 23 16 36

@marandaneto
Copy link
Member

@alekseyrozh the issue is the F8.c which would tell what's the error about.
I don't see how

config.logger.log("API Key: ${config.apiKey} already has a PostHog instance.")
would throw InstantiationError, so I wonder if the minifyEnabled messed up the line numbers.

@marandaneto
Copy link
Member

Maybe I found a possible problem #140

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

Successfully merging a pull request may close this issue.

2 participants