Tencent/tinker · error · IllegalStateException

TinkerApplication is not initialized.

Error message

TinkerApplication is not initialized.

What it means

TinkerApplication.getInstance() returns the process-wide TinkerApplication singleton stored in SELF_HOLDER, which is set only when the Application instance is constructed. This IllegalStateException means getInstance() was called before any TinkerApplication subclass was instantiated — typically from static initializers, ContentProviders that run before Application, or code running in a process where Tinker is not set up.

Source

Thrown at tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/app/TinkerApplication.java:114

    protected TinkerApplication(int tinkerFlags, String delegateClassName,
                                String loaderClassName, boolean tinkerLoadVerifyFlag,
                                boolean useDelegateLastClassLoader, boolean useInterpretModeOnSupported32BitSystem) {
        synchronized (SELF_HOLDER) {
            SELF_HOLDER[0] = this;
        }
        this.tinkerFlags = tinkerFlags;
        this.delegateClassName = delegateClassName;
        this.loaderClassName = loaderClassName;
        this.tinkerLoadVerifyFlag = tinkerLoadVerifyFlag;
        this.useDelegateLastClassLoader = useDelegateLastClassLoader;
        this.useInterpretModeOnSupported32BitSystem = useInterpretModeOnSupported32BitSystem;
    }

    public static TinkerApplication getInstance() {
        synchronized (SELF_HOLDER) {
            if (SELF_HOLDER[0] == null) {
                throw new IllegalStateException("TinkerApplication is not initialized.");
            }
            return SELF_HOLDER[0];
        }
    }

    private void loadTinker() {
        try {
            //reflect tinker loader, because loaderClass may be define by user!
            Class<?> tinkerLoadClass = Class.forName(loaderClassName, false, TinkerApplication.class.getClassLoader());
            Method loadMethod = tinkerLoadClass.getMethod(TINKER_LOADER_METHOD, TinkerApplication.class);
            Constructor<?> constructor = tinkerLoadClass.getConstructor();
            tinkerResultIntent = (Intent) loadMethod.invoke(constructor.newInstance(), this);
        } catch (Throwable e) {
            //has exception, put exception error code
            tinkerResultIntent = new Intent();
            ShareIntentUtil.setIntentReturnCode(tinkerResultIntent, ShareConstants.ERROR_LOAD_PATCH_UNKNOWN_EXCEPTION);
            tinkerResultIntent.putExtra(INTENT_PATCH_EXCEPTION, e);
        }

View on GitHub (pinned to 1b7ea02c23)

Solutions

  1. Delay the call until after Application.onCreate (or at least after attachBaseContext finished).
  2. Make sure the android:name in AndroidManifest is the TinkerApplication subclass (or DefaultTinkerApplication-like generated class) for every process that uses Tinker.
  3. Pass the Application/context in from lifecycle callbacks instead of fetching the singleton eagerly.

Example fix

// before
static { TinkerApplication.getInstance().something(); } // runs before Application ctor

// after
@Override public void onCreate() {
    super.onCreate();
    TinkerApplication.getInstance().something(); // safe: instance exists
}
Defensive patterns

Strategy: validation

Validate before calling

// Check before use
if (TinkerApplication.isSelfInitializedCompat()) { // or track Application.onCreate yourself
    TinkerApplication app = TinkerApplication.getInstance();
}

Try / catch

try {
    TinkerApplication app = TinkerApplication.getInstance();
} catch (IllegalStateException e) {
    // Application not constructed yet: defer to onCreate
}

Prevention

When it happens

Trigger: Calling TinkerApplication.getInstance() from a static block, from a ContentProvider.onCreate that precedes Application creation, or from a :subprocess whose manifest application is not the TinkerApplication subclass.

Common situations: Libraries or crash reporters initialized in attachBaseContext reaching for Tinker too early; multi-process apps where a non-main process lacks the Tinker application class.

Related errors


AI-assisted analysis of Tencent/tinker@1b7ea02c23 (2026-08-14). Data as JSON: /api/errors/e9882e6f6cbd17fd. Report an issue: GitHub.