{"record":{"id":"e9882e6f6cbd17fd","repo":"Tencent/tinker","slug":"tinkerapplication-is-not-initialized-e9882e","errorCode":null,"errorMessage":"TinkerApplication is not initialized.","messagePattern":"TinkerApplication is not initialized\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/app/TinkerApplication.java","lineNumber":114,"sourceCode":"\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 = tinkerFlags;\n        this.delegateClassName = delegateClassName;\n        this.loaderClassName = loaderClassName;\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 void loadTinker() {\n        try {\n            //reflect tinker loader, because loaderClass may be define by user!\n            Class<?> tinkerLoadClass = Class.forName(loaderClassName, false, TinkerApplication.class.getClassLoader());\n            Method loadMethod = tinkerLoadClass.getMethod(TINKER_LOADER_METHOD, TinkerApplication.class);\n            Constructor<?> constructor = tinkerLoadClass.getConstructor();\n            tinkerResultIntent = (Intent) loadMethod.invoke(constructor.newInstance(), this);\n        } catch (Throwable e) {\n            //has exception, put exception error code\n            tinkerResultIntent = new Intent();\n            ShareIntentUtil.setIntentReturnCode(tinkerResultIntent, ShareConstants.ERROR_LOAD_PATCH_UNKNOWN_EXCEPTION);\n            tinkerResultIntent.putExtra(INTENT_PATCH_EXCEPTION, e);\n        }","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/app/TinkerApplication.java#L96-L132","documentation":"TinkerApplication.getInstance() returns the process-wide TinkerApplication singleton stored in SELF_HOLDER, which is set only when the Application instance is constructed. This IllegalStateException means getInstance() was called before any TinkerApplication subclass was instantiated — typically from static initializers, ContentProviders that run before Application, or code running in a process where Tinker is not set up.","triggerScenarios":"Calling TinkerApplication.getInstance() from a static block, from a ContentProvider.onCreate that precedes Application creation, or from a :subprocess whose manifest application is not the TinkerApplication subclass.","commonSituations":"Libraries or crash reporters initialized in attachBaseContext reaching for Tinker too early; multi-process apps where a non-main process lacks the Tinker application class.","solutions":["Delay the call until after Application.onCreate (or at least after attachBaseContext finished).","Make sure the android:name in AndroidManifest is the TinkerApplication subclass (or DefaultTinkerApplication-like generated class) for every process that uses Tinker.","Pass the Application/context in from lifecycle callbacks instead of fetching the singleton eagerly."],"exampleFix":"// before\nstatic { TinkerApplication.getInstance().something(); } // runs before Application ctor\n\n// after\n@Override public void onCreate() {\n    super.onCreate();\n    TinkerApplication.getInstance().something(); // safe: instance exists\n}","handlingStrategy":"validation","validationCode":"// Check before use\nif (TinkerApplication.isSelfInitializedCompat()) { // or track Application.onCreate yourself\n    TinkerApplication app = TinkerApplication.getInstance();\n}","typeGuard":null,"tryCatchPattern":"try {\n    TinkerApplication app = TinkerApplication.getInstance();\n} catch (IllegalStateException e) {\n    // Application not constructed yet: defer to onCreate\n}","preventionTips":["Never call getInstance() from static initializers or ContentProviders.","Ensure android:name points to the TinkerApplication subclass in every process using Tinker.","Initialize dependent SDKs in Application.onCreate, not in static blocks."],"tags":["android","lifecycle","singleton","application","tinker"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}