{"record":{"id":"f26604f88ca0ab38","repo":"Tencent/tinker","slug":"tinker-instance-is-already-set","errorCode":null,"errorMessage":"Tinker instance is already set.","messagePattern":"Tinker instance is already set\\.","errorType":"exception","errorClass":"TinkerRuntimeException","httpStatus":null,"severity":"error","filePath":"tinker-android/tinker-android-lib-no-op/src/main/java/com/tencent/tinker/lib/tinker/Tinker.java","lineNumber":119,"sourceCode":"            throw new TinkerRuntimeException(\"you must install tinker before get tinker sInstance\");\n        }\n        synchronized (Tinker.class) {\n            if (sInstance == null) {\n                sInstance = new Builder(context).build();\n            }\n        }\n        return sInstance;\n    }\n\n    /**\n     * create custom tinker by {@link Tinker.Builder}\n     * please do it when very first your app start.\n     *\n     * @param tinker\n     */\n    public static void create(Tinker tinker) {\n        if (sInstance != null) {\n            throw new TinkerRuntimeException(\"Tinker instance is already set.\");\n        }\n        sInstance = tinker;\n    }\n\n    public static boolean isTinkerInstalled() {\n        return sInstalled;\n    }\n\n    /**\n     * you must install tinker first!!\n     *\n     * @param intentResult\n     * @param serviceClass\n     * @param upgradePatch\n     */\n    public void install(Intent intentResult, Class<? extends AbstractResultService> serviceClass,\n                        AbstractPatch upgradePatch) {\n        sInstalled = true;","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-android/tinker-android-lib-no-op/src/main/java/com/tencent/tinker/lib/tinker/Tinker.java#L101-L137","documentation":"Tinker.create(Tinker) is the low-level way to set the singleton (used internally by install/build flows) and throws TinkerRuntimeException(\"Tinker instance is already set.\") if sInstance is already non-null. It exists so the instance can only be bound once per process; a second create indicates duplicated initialization, which Tinker rejects rather than silently replacing configuration.","triggerScenarios":"Calling Tinker.create(...) twice in the same process — e.g. both TinkerInstaller.install() and a manual Builder(...).build()/create() path running, or install invoked from two lifecycle callbacks, or a retained client library re-initializing.","commonSituations":"Migrating from manual Builder+create setup to TinkerInstaller.install and leaving the old path in place; initializing in both a base Application class and a subclass's onCreate; SDKs that embed Tinker initializing on top of the app's own initialization.","solutions":["Pick exactly one initialization path per process: prefer TinkerInstaller.install(...) and delete direct create() calls.","If you must use create(), guard it: only call when the instance is not already set (track with your own static flag or wrap in try-catch during migration).","Move initialization to the earliest single point (Application.attachBaseContext/onCreate) so later re-entry cannot occur."],"exampleFix":"// before\nTinkerInstaller.install(appLike, ...);   // sets sInstance\n...\nTinker.create(new Tinker.Builder(app).build()); // throws: already set\n\n// after\nTinkerInstaller.install(appLike, ...);   // single init path\n// remove the manual Tinker.create(...) call entirely","handlingStrategy":"validation","validationCode":"// use the official installer only, exactly once per process\nif (!Tinker.isTinkerInstalled()) {\n    TinkerInstaller.install(appLike, loadReporter, patchReporter, listener,\n            null, loadVerifyFlag, null);\n}\n// do not call Tinker.create(...) directly","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer TinkerInstaller.install over manual Builder+create","Initialize in one place (earliest Application callback) and remove legacy init paths"],"tags":["android","tinker","initialization","singleton","double-init"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}