{"record":{"id":"709d76348c259aef","repo":"alibaba/arthas","slug":"allserverstart-must-be-initialized-before","errorCode":null,"errorMessage":"AllServerStart must be initialized before!","messagePattern":"AllServerStart must be initialized before!","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/grpc/DemoBootstrap.java","lineNumber":141,"sourceCode":"        String currentDir = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getPath();\n        String STATIC_LOCATION = Paths.get(currentDir, \"static\").toString();\n        NettyHttpServer nettyHttpServer = new NettyHttpServer(HTTP_PORT,STATIC_LOCATION);\n        logger.info(\"start grpc server on port: {}, grpc web proxy server on port: {}, \" +\n                \"http server server on port: {}\", GRPC_PORT,GRPC_WEB_PROXY_PORT,HTTP_PORT);\n        System.out.println(\"Open your web browser and navigate to \" + \"http\" + \"://127.0.0.1:\" + HTTP_PORT + '/' + \"index.html\");\n        nettyHttpServer.start();\n    }\n\n    public synchronized static DemoBootstrap getInstance() throws Throwable {\n        if (demoBootstrap == null) {\n            demoBootstrap = new DemoBootstrap();\n        }\n        return demoBootstrap;\n    }\n\n    public static DemoBootstrap getRunningInstance() {\n        if (demoBootstrap == null) {\n            throw new IllegalStateException(\"AllServerStart must be initialized before!\");\n        }\n        return demoBootstrap;\n    }\n\n    public void execute(Runnable command) {\n        executorService.execute(command);\n    }\n\n\n\n    public static void appendSpyJar(Instrumentation instrumentation) throws IOException {\n        // find spy target/classes directory\n        String file = DemoBootstrap.class.getProtectionDomain().getCodeSource().getLocation().getFile();\n\n        File spyClassDir = new File(file, \"../../../spy/target/classes\").getAbsoluteFile();\n\n        File destJarFile = new File(file, \"../../../spy/target/test-spy.jar\").getAbsoluteFile();\n","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/grpc/DemoBootstrap.java#L123-L159","documentation":"DemoBootstrap.getRunningInstance() throws IllegalStateException when called before the singleton has been initialized via getInstance(). The class is a lazy-initialized server bootstrap: getInstance() creates and starts all servers; getRunningInstance() assumes they are already running. Calling getRunningInstance() first skips initialization and has no server to return.","triggerScenarios":"Invoking DemoBootstrap.getRunningInstance() without a prior successful DemoBootstrap.getInstance() call in the same JVM.","commonSituations":"Startup ordering bug — a component that needs the running bootstrap is initialized before the bootstrap itself; a test or CLI entry point calls getRunningInstance() directly; refactoring moved the getInstance() call behind a condition that evaluated false.","solutions":["Call DemoBootstrap.getInstance() (which initializes and starts servers) before any call to getRunningInstance().","Review startup ordering to ensure the bootstrap is created early in the lifecycle.","If the bootstrap may or may not be started, check with a null-guarding helper or catch IllegalStateException and initialize on demand."],"exampleFix":"// before\nDemoBootstrap bootstrap = DemoBootstrap.getRunningInstance(); // throws\n\n// after\nDemoBootstrap bootstrap = DemoBootstrap.getInstance(); // initializes if needed\n// later, only after init:\nDemoBootstrap running = DemoBootstrap.getRunningInstance();","handlingStrategy":"validation","validationCode":"// Initialize before accessing the running instance\nDemoBootstrap bootstrap;\ntry {\n    bootstrap = DemoBootstrap.getRunningInstance();\n} catch (IllegalStateException e) {\n    bootstrap = DemoBootstrap.getInstance(); // triggers initialization\n}","typeGuard":null,"tryCatchPattern":"try {\n    return DemoBootstrap.getRunningInstance();\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"initialized before\")) {\n        return DemoBootstrap.getInstance();\n    }\n    throw e;\n}","preventionTips":["Call getInstance() early in the application startup sequence.","Do not rely on getRunningInstance() in components that may initialize before the bootstrap."],"tags":["arthas","grpc-web-proxy","lifecycle","singleton","initialization"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}