{"record":{"id":"9b8ead6ae0689a39","repo":"Tencent/tinker","slug":"sharesecuritycheck-init-public-key-fail","errorCode":null,"errorMessage":"ShareSecurityCheck init public key fail","messagePattern":"ShareSecurityCheck init public key fail","errorType":"exception","errorClass":"TinkerRuntimeException","httpStatus":null,"severity":"critical","filePath":"tinker-android/tinker-android-loader-no-op/src/main/java/com/tencent/tinker/loader/shareutil/ShareSecurityCheck.java","lineNumber":173,"sourceCode":"                }\n            }\n        }\n        return false;\n    }\n\n    @SuppressLint(\"PackageManagerGetSignatures\")\n    private void init(Context context) {\n        ByteArrayInputStream stream = null;\n        try {\n            PackageManager pm = context.getPackageManager();\n            String packageName = context.getPackageName();\n            PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);\n            mPublicKeyMd5 = SharePatchFileUtil.getMD5(packageInfo.signatures[0].toByteArray());\n            if (mPublicKeyMd5 == null) {\n                throw new TinkerRuntimeException(\"get public key md5 is null\");\n            }\n        } catch (Exception e) {\n            throw new TinkerRuntimeException(\"ShareSecurityCheck init public key fail\", e);\n        } finally {\n            SharePatchFileUtil.closeQuietly(stream);\n        }\n    }\n}\n","sourceCodeStart":155,"sourceCodeEnd":179,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-android/tinker-android-loader-no-op/src/main/java/com/tencent/tinker/loader/shareutil/ShareSecurityCheck.java#L155-L179","documentation":"ShareSecurityCheck.init wraps its whole body: any exception while fetching PackageManager, calling getPackageInfo with GET_SIGNATURES, or computing the signature md5 is caught and rethrown as TinkerRuntimeException('ShareSecurityCheck init public key fail'). This is the outer guard around error 174 — the app's identity could not be established, so no patch can be trusted.","triggerScenarios":"context.getPackageManager()/getPackageInfo throwing (NameNotFoundException, dead PackageManager transaction in a bad process state); packageInfo.signatures empty on rare ROMs making signatures[0] throw ArrayIndexOutOfBoundsException; the md5-null TinkerRuntimeException from error 174 itself landing in this catch.","commonSituations":"Instant-run-style or instrumented processes where the package context is odd; apps running inside work profiles/containers; heavy task-killer ROMs killing PackageManager binder calls; the underlying md5-null failure (174).","solutions":["Read the caused-by: NameNotFoundException means wrong package context, AIOOBE means empty signatures, TinkerRuntimeException('get public key md5 is null') means issue 174.","Ensure tinker initialization runs in the main process with the application's real Context (not a backup/instrumentation context).","On affected devices, disable patch loading (TinkerInstaller/disable flags) rather than crashing — identity checks failing is unrecoverable in-process.","Upgrade tinker for modern signature APIs (GET_SIGNING_CERTIFICATES) and hardened init."],"exampleFix":"// before\nShareSecurityCheck check = new ShareSecurityCheck(context); // throws TinkerRuntimeException from init\n\n// after\nShareSecurityCheck check;\ntry {\n    check = new ShareSecurityCheck(context);\n} catch (TinkerRuntimeException e) {\n    ShareTinkerLog.e(TAG, \"security check unavailable on this device, disable tinker\", e);\n    TinkerInternals.disableTinkerInternals(context); // or set your own disable flag\n    return;\n}","handlingStrategy":"try-catch","validationCode":"try {\n    context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);\n} catch (Exception e) {\n    // PackageManager unhealthy: skip patch initialization this session\n}","typeGuard":null,"tryCatchPattern":"catch TinkerRuntimeException from ShareSecurityCheck construction -> log cause, disable tinker, continue app without hotpatch","preventionTips":["Initialize tinker in the main process with the real Application context.","Never let a failed security check crash the app — hotpatching is optional capability.","Inspect the caused-by to distinguish package-manager failure from md5-null (174)."],"tags":["signature","security-check","package-manager","initialization"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}