Tencent/tinker · error · IllegalStateException
failed to fetch instance of ActivityThread.
Error message
failed to fetch instance of ActivityThread.
What it means
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.
Source
Thrown at tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/hotplug/ComponentHotplug.java:86
sPMSInterceptor.install();
if (Build.VERSION.SDK_INT < 27) {
sMHMessageInterceptor.install();
} else {
sTinkerHackInstrumentation.install();
}
} catch (Throwable thr) {
uninstall();
throw new UnsupportedEnvironmentException(thr);
}
} else {
ShareTinkerLog.i(TAG, "method install() is not invoked, ignore ensuring operations.");
}
}
private static Handler fetchMHInstance(Context context) {
final Object activityThread = ShareReflectUtil.getActivityThread(context, null);
if (activityThread == null) {
throw new IllegalStateException("failed to fetch instance of ActivityThread.");
}
try {
final Field mHField = ShareReflectUtil.findField(activityThread, "mH");
final Handler mH = (Handler) mHField.get(activityThread);
return mH;
} catch (Throwable thr) {
throw new IllegalStateException(thr);
}
}
public synchronized static void uninstall() {
if (sInstalled) {
try {
sAMSInterceptor.uninstall();
sPMSInterceptor.uninstall();
if (Build.VERSION.SDK_INT < 27) {
sMHMessageInterceptor.uninstall();
} else {View on GitHub (pinned to 1b7ea02c23)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
try {
Object at = ShareReflectUtil.getActivityThread(context, null);
if (at == null) return; // hotplug unsupported here
ShareReflectUtil.findField(at, "mH");
} catch (Throwable t) {
// environment unsupported: skip component hotplug
} Try / catch
try {
ComponentHotplug.install(context);
} catch (UnsupportedEnvironmentException | IllegalStateException e) {
// ActivityThread internals unavailable: degrade to base-manifest components
} Prevention
- Always catch UnsupportedEnvironmentException around ComponentHotplug.install.
- Test hotplug on target OEM ROMs before enabling increment components.
- Keep Tinker updated for new ActivityThread shapes.
When it happens
Trigger: 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.
Common situations: Android P+ hidden API greylisting; OEM frameworks; test environments (Robolectric) lacking a real ActivityThread.
Related errors
- resource references is null
- createDelegate failed
- Cannot query transaction code of performDexOptSecondary.
- Fail to hack resourceImpls field.
- createInlineFence failed
AI-assisted analysis of Tencent/tinker@1b7ea02c23 (2026-08-14).
Data as JSON: /api/errors/86e50342574125ef.
Report an issue: GitHub.