asLody/VirtualApp · critical · IllegalStateException

please call initialize() at first.

Error message

please call initialize() at first.

What it means

IPCBus requires a one-time initialization where an IServerCache implementation is supplied via IPCBus.initialize(cache). checkInitialized() throws this IllegalStateException when register() or get() is called before initialize(). It is a guard against using the IPC bus before its storage layer exists.

Solutions

  1. Call IPCBus.initialize(new IServerCache implementation) in Application.attachBaseContext or onCreate before any register/get call
  2. Verify the module hosting initialize() is loaded in every process that uses IPCBus
  3. Add an explicit init call at the top of the code path that first touches IPCBus

Example fix

// before
IPCBus.register(IUserService.class, new UserService());
// after
IPCBus.initialize(new DefaultServerCache());
IPCBus.register(IUserService.class, new UserService());
Defensive patterns

Strategy: validation

Validate before calling

// reflectively check IPCBus was initialized (no public getter; guard by calling init first)
IPCBus.initialize(new DefaultServerCache()); // idempotent guard before any use

Try / catch

try {
    IPCBus.register(IUserService.class, new UserServiceImpl());
} catch (IllegalStateException e) {
    if (e.getMessage().contains("initialize()")) {
        IPCBus.initialize(new DefaultServerCache());
        IPCBus.register(IUserService.class, new UserServiceImpl());
    }
}

Prevention

When it happens

Trigger: Calling IPCBus.register(interfaceClass, server) or IPCBus.get(interfaceClass) before IPCBus.initialize(cache) has been called anywhere in the process (typically in the Application/attachBaseContext).

Common situations: Forgetting to call initialize in a ContentProvider/Application startup path; a background process or separate virtual process using IPCBus without running the init code; reordering after a refactor moved initialize later than first use.

Related errors


AI-assisted analysis of asLody/VirtualApp@666fefcb5d (2026-09-09). Data as JSON: /api/errors/c127a527fe117ee9. Report an issue: GitHub.

Appendix: source

Thrown at VirtualApp/lib/src/main/java/com/lody/virtual/helper/ipcbus/IPCBus.java:21

import android.os.IBinder;

import java.lang.reflect.Proxy;

/**
 * @author Lody
 */
public class IPCBus {

    private static IServerCache sCache;

    public static void initialize(IServerCache cache) {
        sCache = cache;
    }

    private static void checkInitialized() {
        if (sCache == null) {
            throw new IllegalStateException("please call initialize() at first.");
        }
    }

    public static void register(Class<?> interfaceClass, Object server) {
        checkInitialized();
        ServerInterface serverInterface = new ServerInterface(interfaceClass);
        TransformBinder binder = new TransformBinder(serverInterface, server);
        sCache.join(serverInterface.getInterfaceName(), binder);
    }

    public static <T> T get(Class<?> interfaceClass) {
        checkInitialized();
        ServerInterface serverInterface = new ServerInterface(interfaceClass);
        IBinder binder = sCache.query(serverInterface.getInterfaceName());
        if (binder == null) {
            return null;
        }
        //noinspection unchecked

View on GitHub (pinned to 666fefcb5d)