{"record":{"id":"71dfefdac83e23a6","repo":"Tencent/tinker","slug":"rewritepatchinfofilewithlock-fail-71dfef","errorCode":null,"errorMessage":"rewritePatchInfoFileWithLock fail","messagePattern":"rewritePatchInfoFileWithLock fail","errorType":"exception","errorClass":"TinkerRuntimeException","httpStatus":null,"severity":"error","filePath":"tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/shareutil/SharePatchInfo.java","lineNumber":120,"sourceCode":"\n        return patchInfo;\n    }\n\n    public static boolean rewritePatchInfoFileWithLock(File pathInfoFile, SharePatchInfo info, File lockFile) {\n        if (pathInfoFile == null || info == null || lockFile == null) {\n            return false;\n        }\n        File lockParentFile = lockFile.getParentFile();\n        if (!lockParentFile.exists()) {\n            lockParentFile.mkdirs();\n        }\n        boolean rewriteSuccess;\n        ShareFileLockHelper fileLock = null;\n        try {\n            fileLock = ShareFileLockHelper.getFileLock(lockFile);\n            rewriteSuccess = rewritePatchInfoFile(pathInfoFile, info);\n        } catch (Exception e) {\n            throw new TinkerRuntimeException(\"rewritePatchInfoFileWithLock fail\", e);\n        } finally {\n            try {\n                if (fileLock != null) {\n                    fileLock.close();\n                }\n            } catch (IOException e) {\n                ShareTinkerLog.i(TAG, \"releaseInfoLock error\", e);\n            }\n\n        }\n        return rewriteSuccess;\n    }\n\n    private static SharePatchInfo readAndCheckProperty(File pathInfoFile) {\n        boolean isReadPatchSuccessful = false;\n        int numAttempts = 0;\n        String oldVer = null;\n        String newVer = null;","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/shareutil/SharePatchInfo.java#L102-L138","documentation":"SharePatchInfo.rewritePatchInfoFileWithLock locks the info lock file and serializes the new patch info; any exception from locking or the rewrite is wrapped as TinkerRuntimeException(\"rewritePatchInfoFileWithLock fail\", e). It is the write-side counterpart of error 213 and typically indicates storage or lock problems.","triggerScenarios":"Calling rewritePatchInfoFileWithLock(pathInfoFile, info, lockFile) when the lock cannot be acquired or writing/serializing the properties file throws (disk full, permissions, concurrent writer).","commonSituations":"Low storage during patch apply; multiple processes patching concurrently; lock file left held after a crash; info directory deleted underneath the operation.","solutions":["Check the chained cause: IOException from locking vs write failure.","Verify free space and write permissions on the tinker info directory.","Serialize patch operations to a single process.","Clean the tinker directory / reinstall if the lock state is stuck, then reapply the patch.","Catch TinkerRuntimeException and surface a retryable patch-apply failure."],"exampleFix":"// before\nSharePatchInfo.rewritePatchInfoFileWithLock(infoFile, info, lockFile);\n// after\ntry {\n    SharePatchInfo.rewritePatchInfoFileWithLock(infoFile, info, lockFile);\n} catch (TinkerRuntimeException e) {\n    ShareTinkerLog.e(TAG, \"rewrite patch info fail, will retry on next apply\", e);\n}","handlingStrategy":"retry","validationCode":"File parent = pathInfoFile.getParentFile();\nif (parent == null || (!parent.exists() && !parent.mkdirs()) || !parent.canWrite()) {\n    // cannot write info file: abort before locking\n}\nif (getFreeBytes(parent) < MIN_FREE_BYTES) {\n    // low storage: defer patch apply\n}","typeGuard":null,"tryCatchPattern":"try {\n    SharePatchInfo.rewritePatchInfoFileWithLock(infoFile, info, lockFile);\n} catch (TinkerRuntimeException e) {\n    // transient lock/disk issue: schedule patch apply retry on next launch\n}","preventionTips":["Check free disk space before applying patches.","Serialize patch apply to one process.","Make patch apply idempotent and restartable so retries are safe."],"tags":["android","tinker","patch-info","file-lock","io"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}