{"record":{"id":"7d803b91bad4104e","repo":"Tencent/tinker","slug":"tinkerflag-is-already-set","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-no-op/src/main/java/com/tencent/tinker/lib/tinker/Tinker.java","lineNumber":316,"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":298,"sourceCodeEnd":334,"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#L298-L334","documentation":"Tinker.Builder.tinkerFlags(int) is a set-once fluent setter: it throws TinkerRuntimeException(\"tinkerFlag is already set.\") when this.status != -1, i.e. when the same builder has already had its flags configured. The guard catches accidental double-configuration from chaining or repeated calls, which would otherwise silently override the enabled-patch-type bitmask (dex, native lib, resources).","triggerScenarios":"Calling tinkerFlags(...) twice on the same Builder instance — e.g. shared configuration code applying a default bitmask and then caller-specific code applying another, or a copy-pasted chain segment duplicated during refactor.","commonSituations":"A common base method configures TinkerEnabled.ALL and a flavor-specific path then narrows it to TinkerDISABLE or DEX_ONLY; builder instances cached in a field and reused; merging two init code paths during cleanup.","solutions":["Decide the bitmask once and pass it as a parameter to a single tinkerFlags() call.","If defaults plus overrides are needed, compute the final int (e.g. flags &= ~Tinker_ENABLE_NATIVE_LIBRARY) before calling the setter once.","Never reuse a Builder instance; construct a fresh one per initialization."],"exampleFix":"// before\nbuilder.tinkerFlags(TinkerENABLE.ALL);\nif (debugBuild) builder.tinkerFlags(TinkerENABLE.DEX_ONLY); // throws\n\n// after\nint flags = debugBuild ? TinkerENABLE.DEX_ONLY : TinkerENABLE.ALL;\nbuilder.tinkerFlags(flags);","handlingStrategy":"validation","validationCode":"// compute final flags once, then a single setter call\nint flags = TinkerENABLE.ALL;\nif (!nativePatchingEnabled) flags &= ~TinkerENABLE.NATIVE_LIBRARY;\nbuilder.tinkerFlags(flags);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the whole builder chain in one method","Resolve configuration before touching the builder, not on it"],"tags":["android","tinker","builder","configuration"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}