{"record":{"id":"bd7ad3b890e79bd5","repo":"Tencent/tinker","slug":"tinkerapplication-is-not-initialized","errorCode":null,"errorMessage":"TinkerApplication is not initialized.","messagePattern":"TinkerApplication is not initialized\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"tinker-android/tinker-android-loader-no-op/src/main/java/com/tencent/tinker/loader/app/TinkerApplication.java","lineNumber":80,"sourceCode":"    }\n\n    protected TinkerApplication(int tinkerFlags, String delegateClassName,\n                                String loaderClassName, boolean tinkerLoadVerifyFlag,\n                                boolean useDelegateLastClassLoader, boolean useInterpretModeOnSupported32BitSystem) {\n        synchronized (SELF_HOLDER) {\n            SELF_HOLDER[0] = this;\n        }\n        this.tinkerFlags = ShareConstants.TINKER_DISABLE;\n        this.delegateClassName = delegateClassName;\n        this.tinkerLoadVerifyFlag = tinkerLoadVerifyFlag;\n        this.useDelegateLastClassLoader = useDelegateLastClassLoader;\n        this.useInterpretModeOnSupported32BitSystem = useInterpretModeOnSupported32BitSystem;\n    }\n\n    public static TinkerApplication getInstance() {\n        synchronized (SELF_HOLDER) {\n            if (SELF_HOLDER[0] == null) {\n                throw new IllegalStateException(\"TinkerApplication is not initialized.\");\n            }\n            return SELF_HOLDER[0];\n        }\n    }\n\n    private ApplicationLike createDelegate(Application app,\n                                           int tinkerFlags,\n                                           String delegateClassName,\n                                           boolean tinkerLoadVerifyFlag,\n                                           long applicationStartElapsedTime,\n                                           long applicationStartMillisTime,\n                                           Intent resultIntent) {\n        try {\n            // Use reflection to create the delegate so it doesn't need to go into the primary dex.\n            // And we can also patch it\n            final Class<?> delegateClass = Class.forName(delegateClassName, false, mCurrentClassLoader);\n            final Constructor<?> constructor = delegateClass.getConstructor(Application.class, int.class, boolean.class,\n                    long.class, long.class, Intent.class);","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-android/tinker-android-loader-no-op/src/main/java/com/tencent/tinker/loader/app/TinkerApplication.java#L62-L98","documentation":"TinkerApplication.getInstance() returns the process-wide singleton stored in SELF_HOLDER, which is set in the TinkerApplication constructor. If the application class has not yet been constructed, the holder slot is null and getInstance throws IllegalStateException. This almost always means the caller invoked Tinker.with()/getInstance() before Application creation or in a context where the custom TinkerApplication is not the manifest application.","triggerScenarios":"Calling TinkerApplication.getInstance() (directly or via Tinker.with(context)) before the TinkerApplication subclass instance was constructed — e.g. from a static initializer, ContentProvider.onCreate() that runs before Application, or from code running in a process whose manifest application is not the TinkerApplication.","commonSituations":"Using a ContentProvider or backup agent that initializes before the Application; manifest not declaring the generated TinkerApplication subclass (or DefaultTinkerApplication); proguard stripping/renaming the application class; calling Tinker APIs from instrumented tests where the real Application never runs.","solutions":["Ensure the manifest android:name points to your TinkerApplication subclass (or the generated DefaultTinkerApplication).","Move Tinker.with()/TinkerInstaller calls into Application.onCreate()/onBaseContextAttached() or later in the lifecycle, never into static blocks or ContentProviders that initialize first.","Delay provider initialization (setProviderEnabled(false) on lazy providers, or init them in Application.onCreate()).","In tests, construct or mock the Application before hitting Tinker APIs."],"exampleFix":"// before (crashes in a ContentProvider that starts before the app)\npublic boolean onCreate() {\n    Tinker.with(getContext()).install(loadReporter); // IllegalStateException\n    return true;\n}\n\n// after (defer to Application)\npublic class MyApplication extends TinkerApplication {\n    @Override public void onCreate() {\n        super.onCreate();\n        Tinker.install(this); // safe: application constructed\n    }\n}","handlingStrategy":"validation","validationCode":"// guard any early Tinker access (e.g. in providers)\nprivate static boolean tinkerReady() {\n    try {\n        TinkerApplication.getInstance();\n        return true;\n    } catch (IllegalStateException e) {\n        return false;\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    Tinker.with(context).install(reporter);\n} catch (IllegalStateException e) {\n    // Application not constructed yet: defer init to Application.onCreate()\n}","preventionTips":["Set android:name to your TinkerApplication subclass in the manifest","Initialize tinker only from Application.onCreate() or later","Make ContentProviders lazy so they don't run before the Application"],"tags":["tinker","android","initialization-order","application-lifecycle"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}