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

Crash on app process restart #1529

Closed
emartynov opened this issue Aug 12, 2019 · 9 comments · Fixed by #1531
Closed

Crash on app process restart #1529

emartynov opened this issue Aug 12, 2019 · 9 comments · Fixed by #1531
Milestone

Comments

@emartynov
Copy link

emartynov commented Aug 12, 2019

Description

I think we had something similar already. Here is crash reported after update from alpha to beta:


Caused by kotlin.UninitializedPropertyAccessException
lateinit property application has not been initialized
leakcanary.internal.InternalLeakCanary.getApplication (InternalLeakCanary.kt:35)
leakcanary.DefaultOnHeapAnalyzedListener$Companion.create (DefaultOnHeapAnalyzedListener.kt:78)
leakcanary.LeakCanary$Config.<init> (LeakCanary.kt:92)
leakcanary.internal.InternalLeakCanary.getNoInstallConfig (InternalLeakCanary.kt:52)
leakcanary.LeakCanary.<clinit> (LeakCanary.kt:147)

Steps to Reproduce

Unfortunately no sample project yet.

Expected behaviour:

Obvious - don't crash.

Version Information

  • LeakCanary version: 2-beta-2
  • Android OS version: Android 9
  • Gradle version: 5.5.1

Additional Information

Looks like it is crashing after process reboot.

@emartynov
Copy link
Author

The code that is causing it is


    fun install() {
        LeakCanary.config = LeakCanary.config.copy(referenceMatchers = excludeSamsungIssues()) //<-- crash is here
    }

    /**
     * LeakCanary is only excluding the SemClipboardManager and SemEmergencyManager until Android API 24,
     * but still occurs on Android API 25.
     */
    private fun excludeSamsungIssues(): List<ReferenceMatcher> {
        return AndroidReferenceMatchers.appDefaults +
                AndroidReferenceMatchers.staticFieldLeak(
                        className = "com.samsung.android.content.clipboard.SemClipboardManager",
                        fieldName = "mContext",
                        description = "SemClipboardManager is held in memory by an anonymous inner class " +
                                "implementation of android.os.Binder, thereby leaking an activity context.",
                        patternApplies = {
                            manufacturer == "samsung" && sdkInt <= N_MR1
                        }
                ) +
                AndroidReferenceMatchers.staticFieldLeak(
                        "com.samsung.android.emergencymode.SemEmergencyManager",
                        "mContext",
                        description = "SemEmergencyManager is a static singleton that leaks a DecorContext.",
                        patternApplies = {
                            manufacturer == "samsung" && sdkInt <= N_MR1
                        }
                )
    }

@emartynov emartynov changed the title Crash on app start Crash on app process restart Aug 12, 2019
@emartynov
Copy link
Author

Here is sample project https://github.com/emartynov/LeakCanaryProcessRestart

You have to use 3.5 AS to build it.

Check App class to uncomment lines to reproduce the crash.

@pyricau pyricau added this to the 2.0 Next Release milestone Aug 12, 2019
@pyricau
Copy link
Member

pyricau commented Aug 12, 2019

Thanks for the sample project, that definitely helps!

pyricau added a commit that referenced this issue Aug 12, 2019
Fixes #1529

I wish I could write a test for this unfortunately that seems tricky without creating an entirely new and separate test module.
pyricau added a commit that referenced this issue Aug 12, 2019
Fixes #1529

I wish I could write a test for this unfortunately that seems tricky without creating an entirely new and separate test module.
@npike
Copy link

npike commented Mar 11, 2020

I am still seeing this crash on 2.2 when restarting the app using Process Phoenix. Any ideas?

@emartynov
Copy link
Author

What do you see in the log?

@npike
Copy link

npike commented Mar 11, 2020

Here's the stacktrace:

java.lang.RuntimeException: Unable to create application com.phunware.wallet.WalletApp: kotlin.UninitializedPropertyAccessException: lateinit property application has not been initialized
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6465)
        at android.app.ActivityThread.access$1300(ActivityThread.java:219)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: kotlin.UninitializedPropertyAccessException: lateinit property application has not been initialized
        at leakcanary.internal.InternalLeakCanary.setEnabledBlocking(InternalLeakCanary.kt:290)
        at leakcanary.LeakCanary.showLeakDisplayActivityLauncherIcon(LeakCanary.kt:337)
        at com.phunware.wallet.core.DebugEnvironment.leakCanaryConfig(DebugEnvironment.kt:145)
        at com.phunware.wallet.core.DebugEnvironment.setup(DebugEnvironment.kt:111)
        at com.phunware.wallet.WalletApp.onCreate(WalletApp.kt:76)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1182)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6460)
        at android.app.ActivityThread.access$1300(ActivityThread.java:219) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7356) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 

@emartynov
Copy link
Author

Do you disable LeakCanary providers in the manifest? Probably not otherwise it would not start at all.

@npike
Copy link

npike commented Mar 11, 2020

In our app when a certain compile time feature flag is enabled, we manually disable leakcanary like so:

LeakCanary.showLeakDisplayActivityLauncherIcon(false)
LeakCanary.config = LeakCanary.config.copy(dumpHeap = false)
AppWatcher.config = AppWatcher.config.copy(enabled = false)

From the stacktrace it would seem that calling showLeakDisplayActivityLauncherIcon while in the ProcessPhoenix process is the issue... so as a workaround for now it looks like I can wrap this in if (!ProcessPhoenix.isPhoenixProcess(context)) {

@pyricau pyricau reopened this Mar 18, 2020
@pyricau
Copy link
Member

pyricau commented Apr 15, 2022

Generally should not interact with LeakCanary APIs when it hasn't been installed.

@pyricau pyricau closed this as completed Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants