{"record":{"id":"6a111e3a6e69d1be","repo":"Tencent/matrix","slug":"zipentry-is-null-when-get-from-oldapk","errorCode":null,"errorMessage":"zipEntry is null when get from oldApk","messagePattern":"zipEntry is null when get from oldApk","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-android/src/main/java/com/tencent/matrix/resource/hproflib/HprofBufferShrinker.java","lineNumber":110,"sourceCode":"            MatrixLog.e(TAG, \"save property error:\" + throwable);\n            return false;\n        } finally {\n            MatrixUtil.closeQuietly(propertiesOutputStream);\n        }\n\n        TinkerZipOutputStream out = null;\n        TinkerZipFile zipFile = null;\n        try {\n\n            out = new TinkerZipOutputStream(new BufferedOutputStream(new FileOutputStream(tempFile)));\n\n            zipFile = new TinkerZipFile(shrinkResultFile);\n            final Enumeration<? extends TinkerZipEntry> entries = zipFile.entries();\n\n            while (entries.hasMoreElements()) {\n                TinkerZipEntry zipEntry = entries.nextElement();\n                if (zipEntry == null) {\n                    throw new RuntimeException(\"zipEntry is null when get from oldApk\");\n                }\n                String name = zipEntry.getName();\n                if (name.contains(\"../\")) {\n                    continue;\n                }\n                TinkerZipUtil.extractTinkerEntry(zipFile, zipEntry, out);\n            }\n            Long crc = getCRC32(propertiesFile);\n            if (crc == null) {\n                MatrixLog.e(TAG, \"new crc is null\");\n                return false;\n            }\n            TinkerZipEntry propertyEntry = new TinkerZipEntry(propertiesFile.getName());\n            // add property file\n            TinkerZipUtil.extractLargeModifyFile(propertyEntry, propertiesFile, crc, out);\n        } catch (IOException e) {\n            MatrixLog.e(TAG, \"zip property error:\" + e);\n            return false;","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-android/src/main/java/com/tencent/matrix/resource/hproflib/HprofBufferShrinker.java#L92-L128","documentation":"HprofBufferShrinker.addExtraInfo() rebuilds the shrunk APK by enumerating entries of the old APK's TinkerZipFile and copying each into the output. Although Enumeration.nextElement() is typed as possibly-null in this Tinker zip implementation, the library defensively throws RuntimeException if a null entry is ever produced, indicating a corrupted or unexpected zip structure.","triggerScenarios":"During addExtraInfo(), iterating zipFile.entries() of the shrinkResultFile (old APK) yields a null TinkerZipEntry from nextElement().","commonSituations":"Corrupted or partially written APK/zip file (interrupted download or build); an apk produced by a tool that emits entries the Tinker zip reader mis-parses; disk-full during prior shrink step leaving a truncated archive.","solutions":["Verify the input APK is a valid, complete zip (e.g. unzip -t oldApk) and re-obtain it if corrupted.","Regenerate the shrunk file: delete shrinkResultFile and rerun the shrink pipeline to rule out a stale/partial output.","Check free disk space and ensure the process writing the apk completed before HprofBufferShrinker reads it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"File f = new File(shrinkResultPath);\nif (!f.isFile() || f.length() == 0) {\n    throw new IOException(\"old apk missing or empty: \" + shrinkResultPath);\n}","typeGuard":null,"tryCatchPattern":"try {\n    shrinker.addExtraInfo(...);\n} catch (RuntimeException e) {\n    Log.e(TAG, \"old apk unreadable, regenerate\", e);\n}","preventionTips":["Verify APK integrity (zip central directory) before running the shrink pipeline.","Regenerate the shrunk file on every run instead of reusing stale outputs.","Check disk space before writing intermediate apk files."],"tags":["android","zip","corrupted-file","hprof"],"backgroundTag":"file-read-failed","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}