{"record":{"id":"0e6a52c0bc67da98","repo":"Tencent/tinker","slug":"patch-file-is-null","errorCode":null,"errorMessage":"patch file is null.","messagePattern":"patch file is null\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"tinker-commons/src/main/java/com/tencent/tinker/commons/dexpatcher/DexPatchApplier.java","lineNumber":119,"sourceCode":"    public DexPatchApplier(InputStream oldDexIn, InputStream patchFileIn) throws IOException {\n        this(new Dex(oldDexIn), new DexPatchFile(patchFileIn));\n    }\n\n    public DexPatchApplier(\n            Dex oldDexIn,\n            DexPatchFile patchFileIn\n    ) {\n        this.oldDex = oldDexIn;\n        this.patchFile = patchFileIn;\n        this.patchedDex = new Dex(patchFileIn.getPatchedDexSize());\n        this.oldToPatchedIndexMap = new SparseIndexMap();\n    }\n\n    public void executeAndSaveTo(OutputStream out) throws IOException {\n        // Before executing, we should check if this patch can be applied to\n        // old dex we passed in.\n        if (this.patchFile == null) {\n            throw new IllegalArgumentException(\"patch file is null.\");\n        }\n        if (this.patchFile.getVersion() > DexPatchFile.VERSION_02) {\n            final int oldDexAPI = this.oldDex.getTableOfContents().api;\n            final int expectedOldDexAPI = this.patchFile.getOldDexAPI();\n            if (oldDexAPI != expectedOldDexAPI) {\n                throw new IOException(\"old dex version mismatch! expetced: \"\n                        + expectedOldDexAPI + \", actual: \" + oldDexAPI);\n            }\n        }\n        byte[] oldDexSign = this.oldDex.computeSignature(false);\n        if (oldDexSign == null) {\n            throw new IOException(\"failed to compute old dex's signature.\");\n        }\n        byte[] oldDexSignInPatchFile = this.patchFile.getOldDexSignature();\n        if (CompareUtils.uArrCompare(oldDexSign, oldDexSignInPatchFile) != 0) {\n            throw new IOException(\n                    String.format(\n                            \"old dex signature mismatch! expected: %s, actual: %s\",","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-commons/src/main/java/com/tencent/tinker/commons/dexpatcher/DexPatchApplier.java#L101-L137","documentation":"IllegalArgumentException from DexPatchApplier.executeAndSaveTo: the patch file object is null. The applier requires a valid DexPatchFile (already parsed from a .dex patch stream) before it can apply operations and write the patched dex.","triggerScenarios":"Constructing DexPatchApplier(oldDex, null) or otherwise invoking executeAndSaveTo on an applier whose patchFile field is null (e.g., a failed patch-file parse left a null reference that was still passed on).","commonSituations":"Custom dex-patching pipelines that read the patch from a stream that failed earlier; logic that constructs the applier before validating the patch input.","solutions":["Parse and validate the DexPatchFile (it throws on bad magic/version in its constructor) before creating the applier","Null-check the patch source and fail fast with a clear message upstream","Ensure the patch entry extracted from the patch zip actually exists before decoding it"],"exampleFix":"// before\nnew DexPatchApplier(oldDex, null).executeAndSaveTo(out);\n\n// after\nif (patchFile == null) throw new IOException(\"no patch entry for this dex\");\nnew DexPatchApplier(oldDex, patchFile).executeAndSaveTo(out);","handlingStrategy":"validation","validationCode":"if (patchFile == null) {\n    throw new IOException(\"missing dex patch entry; skip apply\");\n}\nDexPatchApplier applier = new DexPatchApplier(oldDex, patchFile);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Construct DexPatchFile eagerly so bad magic/version fail before the applier exists","Never build the applier from a possibly-failed extraction result without a null check"],"tags":["dexpatcher","null-argument","tinker","validation"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}