{"record":{"id":"86e50342574125ef","repo":"Tencent/tinker","slug":"failed-to-fetch-instance-of-activitythread","errorCode":null,"errorMessage":"failed to fetch instance of ActivityThread.","messagePattern":"failed to fetch instance of ActivityThread\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/hotplug/ComponentHotplug.java","lineNumber":86,"sourceCode":"                sPMSInterceptor.install();\n                if (Build.VERSION.SDK_INT < 27) {\n                    sMHMessageInterceptor.install();\n                } else {\n                    sTinkerHackInstrumentation.install();\n                }\n            } catch (Throwable thr) {\n                uninstall();\n                throw new UnsupportedEnvironmentException(thr);\n            }\n        } else {\n            ShareTinkerLog.i(TAG, \"method install() is not invoked, ignore ensuring operations.\");\n        }\n    }\n\n    private static Handler fetchMHInstance(Context context) {\n        final Object activityThread = ShareReflectUtil.getActivityThread(context, null);\n        if (activityThread == null) {\n            throw new IllegalStateException(\"failed to fetch instance of ActivityThread.\");\n        }\n        try {\n            final Field mHField = ShareReflectUtil.findField(activityThread, \"mH\");\n            final Handler mH = (Handler) mHField.get(activityThread);\n            return mH;\n        } catch (Throwable thr) {\n            throw new IllegalStateException(thr);\n        }\n    }\n\n    public synchronized static void uninstall()  {\n        if (sInstalled) {\n            try {\n                sAMSInterceptor.uninstall();\n                sPMSInterceptor.uninstall();\n                if (Build.VERSION.SDK_INT < 27) {\n                    sMHMessageInterceptor.uninstall();\n                } else {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/hotplug/ComponentHotplug.java#L68-L104","documentation":"ComponentHotplug (incremental activity/service hot-plugging) hooks ActivityThread.mH to intercept component lifecycle messages. fetchMHInstance calls ShareReflectUtil.getActivityThread(context, null) and throws this IllegalStateException when it cannot obtain the ActivityThread instance, meaning the component-hotplug interceptor cannot be installed.","triggerScenarios":"Reflection into android.app.ActivityThread (currentActivityThread field or static ActivityThread field) returning null on ROMs where it is renamed, blocked by hidden-API restrictions, or where the class was shaded/repackaged by the OEM.","commonSituations":"Android P+ hidden API greylisting; OEM frameworks; test environments (Robolectric) lacking a real ActivityThread.","solutions":["Update Tinker to a release supporting the device's API level.","If using ComponentHotplug, guard it with try-catch for UnsupportedEnvironmentException/IllegalStateException and degrade to non-hotplug mode (components declared in the base manifest).","Avoid enabling incremental-component hotplug on the affected ROM via server-side config."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"try {\n    Object at = ShareReflectUtil.getActivityThread(context, null);\n    if (at == null) return; // hotplug unsupported here\n    ShareReflectUtil.findField(at, \"mH\");\n} catch (Throwable t) {\n    // environment unsupported: skip component hotplug\n}","typeGuard":null,"tryCatchPattern":"try {\n    ComponentHotplug.install(context);\n} catch (UnsupportedEnvironmentException | IllegalStateException e) {\n    // ActivityThread internals unavailable: degrade to base-manifest components\n}","preventionTips":["Always catch UnsupportedEnvironmentException around ComponentHotplug.install.","Test hotplug on target OEM ROMs before enabling increment components.","Keep Tinker updated for new ActivityThread shapes."],"tags":["android","reflection","activitythread","hotplug","tinker"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}