{"record":{"id":"b6ef6fceb7790f21","repo":"Tencent/tinker","slug":"tinkerflag-is-already-set-b6ef6f","errorCode":null,"errorMessage":"tinkerFlag is already set.","messagePattern":"tinkerFlag is already set\\.","errorType":"exception","errorClass":"TinkerRuntimeException","httpStatus":null,"severity":"error","filePath":"tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/tinker/Tinker.java","lineNumber":367,"sourceCode":"            if (context == null) {\n                throw new TinkerRuntimeException(\"Context must not be null.\");\n            }\n            this.context = context;\n            this.mainProcess = TinkerServiceInternals.isInMainProcess(context);\n            this.patchProcess = TinkerServiceInternals.isInTinkerPatchServiceProcess(context);\n            this.patchDirectory = SharePatchFileUtil.getPatchDirectory(context);\n            if (this.patchDirectory == null) {\n                ShareTinkerLog.e(TAG, \"patchDirectory is null!\");\n                return;\n            }\n            this.patchInfoFile = SharePatchFileUtil.getPatchInfoFile(patchDirectory.getAbsolutePath());\n            this.patchInfoLockFile = SharePatchFileUtil.getPatchInfoLockFile(patchDirectory.getAbsolutePath());\n            ShareTinkerLog.w(TAG, \"tinker patch directory: %s\", patchDirectory);\n        }\n\n        public Builder tinkerFlags(int tinkerFlags) {\n            if (this.status != -1) {\n                throw new TinkerRuntimeException(\"tinkerFlag is already set.\");\n            }\n            this.status = tinkerFlags;\n            return this;\n        }\n\n        public Builder tinkerLoadVerifyFlag(Boolean verifyMd5WhenLoad) {\n            if (verifyMd5WhenLoad == null) {\n                throw new TinkerRuntimeException(\"tinkerLoadVerifyFlag must not be null.\");\n            }\n            if (this.tinkerLoadVerifyFlag != null) {\n                throw new TinkerRuntimeException(\"tinkerLoadVerifyFlag is already set.\");\n            }\n            this.tinkerLoadVerifyFlag = verifyMd5WhenLoad;\n            return this;\n        }\n\n        public Builder loadReport(LoadReporter loadReporter) {\n            if (loadReporter == null) {","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/tinker/Tinker.java#L349-L385","documentation":"Builder.tinkerFlags(int) may only be called once. The builder tracks whether status was already assigned (status != -1) and throws on a second call to prevent ambiguous flag configuration (e.g., one call enabling only dex, another enabling only so).","triggerScenarios":"Chaining or repeating tinkerFlags(...) twice on the same Builder instance — commonly when one shared builder is reused across init paths, or a helper method adds flags in addition to explicit call-site configuration.","commonSituations":"A base init method sets tinkerFlags(TINKER_DEX) and a feature module calls tinkerFlags(TINKER_DEX | TINKER_NATIVE) on the same builder; copy-pasted config blocks; builders stored as fields and reused after orientation/process re-entry.","solutions":["Set tinkerFlags exactly once, computing the final mask before calling the builder.","Compose flags in a variable (dex | native | res as needed) rather than calling the setter repeatedly.","Create a fresh Builder per initialization instead of reusing a stored one."],"exampleFix":"// before\nbuilder.tinkerFlags(TINKER_DEX);\nbuilder.tinkerFlags(TINKER_NATIVE); // throws\n\n// after\nint flags = ShareConstants.TINKER_DEX | ShareConstants.TINKER_NATIVE;\nbuilder.tinkerFlags(flags);","handlingStrategy":"validation","validationCode":"int flags = 0;\nif (dexEnabled) flags |= ShareConstants.TINKER_DEX;\nif (nativeEnabled) flags |= ShareConstants.TINKER_NATIVE;\nif (resEnabled) flags |= ShareConstants.TINKER_RESOURCES;\nbuilder.tinkerFlags(flags); // single call with the composed mask","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compose the flag mask in a local variable and call tinkerFlags once.","Keep builder configuration in one method owned by the app module.","Create a new Builder instance per initialization instead of reusing stored ones."],"tags":["tinker","android","builder","configuration","double-init"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}