{"record":{"id":"2b99f88ca59cbf90","repo":"Tencent/tinker","slug":"bad-mode-mode","errorCode":null,"errorMessage":"Bad mode: ${mode}","messagePattern":"Bad mode: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"third-party/tinker-ziputils/src/main/java/com/tencent/tinker/ziputils/ziputil/TinkerZipFile.java","lineNumber":134,"sourceCode":"    public TinkerZipFile(String name) throws IOException {\n        this(new File(name), OPEN_READ);\n    }\n    /**\n     * Constructs a new {@code ZipFile} allowing access to the given file.\n     *\n     * <p>UTF-8 is used to decode all comments and entry names in the file.\n     *\n     * <p>The {@code mode} must be either {@code OPEN_READ} or {@code OPEN_READ|OPEN_DELETE}.\n     * If the {@code OPEN_DELETE} flag is supplied, the file will be deleted at or before the\n     * time that the {@code ZipFile} is closed (the contents will remain accessible until\n     * this {@code ZipFile} is closed); it also calls {@code File.deleteOnExit}.\n     *\n     * @throws IOException if an {@code IOException} occurs.\n     */\n    public TinkerZipFile(File file, int mode) throws IOException {\n        filename = file.getPath();\n        if (mode != OPEN_READ && mode != (OPEN_READ | OPEN_DELETE)) {\n            throw new IllegalArgumentException(\"Bad mode: \" + mode);\n        }\n        if ((mode & OPEN_DELETE) != 0) {\n            fileToDeleteOnClose = file;\n            fileToDeleteOnClose.deleteOnExit();\n        } else {\n            fileToDeleteOnClose = null;\n        }\n        raf = new RandomAccessFile(filename, \"r\");\n\n        readCentralDir();\n        // guard.open(\"close\");\n    }\n\n    /**\n     * Returns true if the string is null or 0-length.\n     * @param str the string to be examined\n     * @return true if str is null or zero length\n     */","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/third-party/tinker-ziputils/src/main/java/com/tencent/tinker/ziputils/ziputil/TinkerZipFile.java#L116-L152","documentation":"TinkerZipFile's constructor only permits mode == OPEN_READ or mode == OPEN_READ|OPEN_DELETE; anything else throws IllegalArgumentException('Bad mode') before the file is opened. OPEN_DELETE makes the file delete-on-close. Passing plain 0, OPEN_DELETE alone, or invented flag values is rejected because the class only supports reading.","triggerScenarios":"new TinkerZipFile(file, mode) with mode outside {OPEN_READ, OPEN_READ|OPEN_DELETE} — e.g. mode = 0, mode = OPEN_DELETE without OPEN_READ, or OR-ing in a write flag from java.util.zip.ZipFile (this class has no write mode).","commonSituations":"Copying constructor calls from code that targeted java.util.zip.ZipFile with different constants; building the mode dynamically from user flags where the read bit can end up unset; version differences where a constant moved between classes.","solutions":["Use exactly TinkerZipFile.OPEN_READ, or OPEN_READ|TinkerZipFile.OPEN_DELETE if you want delete-on-close.","Reference the constants from TinkerZipFile itself, not from java.util.zip.ZipFile or literal ints.","If you constructed a combined mode variable, assert (mode & ~OPEN_DELETE) == OPEN_READ before calling the constructor."],"exampleFix":"// before\nnew TinkerZipFile(new File(path), ZipFile.OPEN_READ | someFlag);\n\n// after\nnew TinkerZipFile(new File(path), TinkerZipFile.OPEN_READ);","handlingStrategy":"validation","validationCode":"int mode = TinkerZipFile.OPEN_READ;\nif (deleteOnClose) {\n    mode |= TinkerZipFile.OPEN_DELETE;\n}\nassert (mode & ~TinkerZipFile.OPEN_DELETE) == TinkerZipFile.OPEN_READ;\nTinkerZipFile zf = new TinkerZipFile(file, mode);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build the mode only from TinkerZipFile's own constants.","Never import ZipFile constants from java.util.zip for this class.","Assert the mode shape in debug builds to catch flag-combination regressions."],"tags":["zip","validation","api-misuse","tinker"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}