{"record":{"id":"3c0d3edea7da17e1","repo":"quarkusio/quarkus","slug":"command-line-arguments-not-available-during-static","errorCode":null,"errorMessage":"Command line arguments not available during static init","messagePattern":"Command line arguments not available during static init","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"core/runtime/src/main/java/io/quarkus/runtime/StartupContext.java","lineNumber":55,"sourceCode":"                    throw new IllegalArgumentException(\"Extension passed an invalid shutdown handler\");\n                }\n            }\n\n            @Override\n            public void addLastShutdownTask(Runnable runnable) {\n                if (runnable != null) {\n                    lastShutdownTasks.addFirst(runnable);\n                } else {\n                    throw new IllegalArgumentException(\"Extension passed an invalid last shutdown handler\");\n                }\n            }\n        };\n        values.put(ShutdownContext.class.getName(), shutdownContext);\n        values.put(RAW_COMMAND_LINE_ARGS, new Supplier<String[]>() {\n            @Override\n            public String[] get() {\n                if (commandLineArgs == null) {\n                    throw new RuntimeException(\"Command line arguments not available during static init\");\n                }\n                return commandLineArgs;\n            }\n        });\n    }\n\n    public void putValue(String name, Object value) {\n        values.put(name, value);\n    }\n\n    public Object getValue(String name) {\n        return values.get(name);\n    }\n\n    @Override\n    public void close() {\n        runAllAndClear(shutdownTasks, ShutdownAction.SHUTDOWN_TASK);\n        runAllAndClear(lastShutdownTasks, ShutdownAction.LAST_SHUTDOWN_TASK);","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/core/runtime/src/main/java/io/quarkus/runtime/StartupContext.java#L37-L73","documentation":"StartupContext exposes raw command line args via a lazy Supplier; if the args were never set (as during native-image static initialization), get() throws. Command line arguments are simply not knowable during static init, so the library fails fast instead of returning null.","triggerScenarios":"Reading StartupValue/StartupContext key RAW_COMMAND_LINE_ARGS (e.g. via startupContext.get(RAW_COMMAND_LINE_ARGS)) during static initialization in a native image, before the args were supplied at run time.","commonSituations":"GraalVM native-image static-init code paths (features, config providers, or extensions reading args at build/static-init time); accessing args from a static initializer of a class loaded during static init.","solutions":["Defer reading RAW_COMMAND_LINE_ARGS until after runtime initialization (e.g. from a StartupEvent observer or runtime init code).","Avoid static initializers that touch StartupContext values in native images; use @InitializeStatically only for static-safe data.","If args are needed during static init, pass them explicitly rather than through StartupContext."],"exampleFix":"// before\nstatic final String[] ARGS = startupContext.get(StartupContext.RAW_COMMAND_LINE_ARGS);\n// after\n@Observes StartupEvent ev -> { String[] args = startupContext.get(StartupContext.RAW_COMMAND_LINE_ARGS); }","handlingStrategy":"validation","validationCode":"// only read args at runtime, never from static initializers:\nif (RuntimeInitPhase.isRuntime()) { args = startupContext.get(StartupContext.RAW_COMMAND_LINE_ARGS); }","typeGuard":null,"tryCatchPattern":"try { args = startupContext.get(StartupContext.RAW_COMMAND_LINE_ARGS); } catch (RuntimeException e) { log.warn(\"args unavailable during static init; deferring\"); args = new String[0]; }","preventionTips":["Never read StartupContext values from static initializers in native images","Read command line args from runtime init or StartupEvent observers","Pass args explicitly to code that must run during static init"],"tags":["quarkus","native-image","static-init","command-line"],"backgroundTag":"unavailable-during-static-init","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}