{"record":{"id":"c127a527fe117ee9","repo":"asLody/VirtualApp","slug":"please-call-initialize-at-first","errorCode":null,"errorMessage":"please call initialize() at first.","messagePattern":"please call initialize\\(\\) at first\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"VirtualApp/lib/src/main/java/com/lody/virtual/helper/ipcbus/IPCBus.java","lineNumber":21,"sourceCode":"\nimport android.os.IBinder;\n\nimport java.lang.reflect.Proxy;\n\n/**\n * @author Lody\n */\npublic class IPCBus {\n\n    private static IServerCache sCache;\n\n    public static void initialize(IServerCache cache) {\n        sCache = cache;\n    }\n\n    private static void checkInitialized() {\n        if (sCache == null) {\n            throw new IllegalStateException(\"please call initialize() at first.\");\n        }\n    }\n\n    public static void register(Class<?> interfaceClass, Object server) {\n        checkInitialized();\n        ServerInterface serverInterface = new ServerInterface(interfaceClass);\n        TransformBinder binder = new TransformBinder(serverInterface, server);\n        sCache.join(serverInterface.getInterfaceName(), binder);\n    }\n\n    public static <T> T get(Class<?> interfaceClass) {\n        checkInitialized();\n        ServerInterface serverInterface = new ServerInterface(interfaceClass);\n        IBinder binder = sCache.query(serverInterface.getInterfaceName());\n        if (binder == null) {\n            return null;\n        }\n        //noinspection unchecked","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/asLody/VirtualApp/blob/666fefcb5d3f39cc944001c3457c38ffd6544c87/VirtualApp/lib/src/main/java/com/lody/virtual/helper/ipcbus/IPCBus.java#L3-L39","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Call IPCBus.initialize(new IServerCache implementation) in Application.attachBaseContext or onCreate before any register/get call","Verify the module hosting initialize() is loaded in every process that uses IPCBus","Add an explicit init call at the top of the code path that first touches IPCBus"],"exampleFix":"// before\nIPCBus.register(IUserService.class, new UserService());\n// after\nIPCBus.initialize(new DefaultServerCache());\nIPCBus.register(IUserService.class, new UserService());","handlingStrategy":"validation","validationCode":"// reflectively check IPCBus was initialized (no public getter; guard by calling init first)\nIPCBus.initialize(new DefaultServerCache()); // idempotent guard before any use","typeGuard":null,"tryCatchPattern":"try {\n    IPCBus.register(IUserService.class, new UserServiceImpl());\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"initialize()\")) {\n        IPCBus.initialize(new DefaultServerCache());\n        IPCBus.register(IUserService.class, new UserServiceImpl());\n    }\n}","preventionTips":["Call IPCBus.initialize in Application.attachBaseContext before anything else","Do the same init in every process entry point (ContentProvider, :process services)","Keep init and first-use in the same startup class to preserve ordering"],"tags":["android","ipc","initialization-order"],"backgroundTag":"module-init-failed","analyzedSha":"666fefcb5d3f39cc944001c3457c38ffd6544c87","analyzedAt":"2026-09-09T11:09:01.694Z","contentChangedAt":"2026-09-09T11:09:01.694Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}