{"record":{"id":"b98e9e1d02fed613","repo":"Tencent/tinker","slug":"getpatchuseemergencymode-but-intent-is-null","errorCode":null,"errorMessage":"getPatchUseEmergencyMode, but intent is null","messagePattern":"getPatchUseEmergencyMode, but intent is null","errorType":"exception","errorClass":"TinkerRuntimeException","httpStatus":null,"severity":"error","filePath":"tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/service/TinkerPatchService.java","lineNumber":99,"sourceCode":"        resultServiceClass = serviceClass;\n        //try to load\n        try {\n            Class.forName(serviceClass.getName());\n        } catch (ClassNotFoundException e) {\n            ShareTinkerLog.printErrStackTrace(TAG, e, \"patch processor class not found.\");\n        }\n    }\n\n    public static String getPatchPathExtra(Intent intent) {\n        if (intent == null) {\n            throw new TinkerRuntimeException(\"getPatchPathExtra, but intent is null\");\n        }\n        return ShareIntentUtil.getStringExtra(intent, PATCH_PATH_EXTRA);\n    }\n\n    public static boolean getPatchUseEmergencyMode(Intent intent) {\n        if (intent == null) {\n            throw new TinkerRuntimeException(\"getPatchUseEmergencyMode, but intent is null\");\n        }\n        return ShareIntentUtil.getBooleanExtra(intent, PATCH_USE_EMERGENCY_MODE, false);\n    }\n\n    public static String getPatchResultExtra(Intent intent) {\n        if (intent == null) {\n            throw new TinkerRuntimeException(\"getPatchResultExtra, but intent is null\");\n        }\n        return ShareIntentUtil.getStringExtra(intent, RESULT_CLASS_EXTRA);\n    }\n\n    @Override\n    protected void onHandleIntent(Intent intent) {\n        increasingPriority();\n        doApplyPatch(this, intent);\n    }\n\n    /**","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/service/TinkerPatchService.java#L81-L117","documentation":"TinkerPatchService.getPatchUseEmergencyMode reads the boolean extra indicating whether the patch should be applied in emergency mode (foreground, screen-on) from the starting intent. Like its sibling accessors, it throws on a null Intent instead of returning the default false.","triggerScenarios":"Calling getPatchUseEmergencyMode(intent) with a null Intent, typically from custom service code or from TinkerPatchService.doApplyPatch itself when onHandleIntent received a null intent (service restarted by the system with null intent redelivery).","commonSituations":"The :patch process being restarted by the OS after a crash, delivering a null intent into onHandleIntent; custom wrappers around the patch service that pass through possibly-null intents.","solutions":["Guard onHandleIntent / custom call sites with a null-intent check that simply returns.","Rely on the standard apply flow (TinkerInstaller.onReceiveUpgradePatch / onReceiveRetryPatchIfNotHandledWithInBackground) so intents are always populated.","Consider START_NOT_STICKY semantics for the patch service to avoid null-intent redeliveries."],"exampleFix":"// before\nboolean emergency = TinkerPatchService.getPatchUseEmergencyMode(intent);\n\n// after\nif (intent == null) return; // service restarted with null intent\nboolean emergency = TinkerPatchService.getPatchUseEmergencyMode(intent);","handlingStrategy":"validation","validationCode":"if (intent == null) return;\nboolean emergency = TinkerPatchService.getPatchUseEmergencyMode(intent);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Short-circuit null intents in onHandleIntent before reading extras.","Prefer the library-provided apply entry points, which construct complete intents.","In unit tests, always build a real Intent with extras instead of passing null."],"tags":["tinker","android","service","intent","null-check"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}