{"record":{"id":"a3428a732edd78fa","repo":"quarkusio/quarkus","slug":"a-context-class-must-either-declare-a-no-args-cons","errorCode":null,"errorMessage":"A context class must either declare a no-args constructor or a constructor that accepts a single parameter of type io.quarkus.arc.CurrentContextFactory","messagePattern":"A context class must either declare a no-args constructor or a constructor that accepts a single parameter of type io\\.quarkus\\.arc\\.CurrentContextFactory","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ContextConfigurator.java","lineNumber":121,"sourceCode":"     * @return self\n     */\n    public ContextConfigurator normal(boolean value) {\n        this.isNormal = value;\n        return this;\n    }\n\n    public ContextConfigurator contextClass(Class<? extends InjectableContext> contextClazz) {\n        if (!Modifier.isPublic(contextClazz.getModifiers())\n                || Modifier.isAbstract(contextClazz.getModifiers())\n                || contextClazz.isAnonymousClass()\n                || contextClazz.isLocalClass()\n                || (contextClazz.getEnclosingClass() != null && !Modifier.isStatic(contextClazz.getModifiers()))) {\n            throw new IllegalArgumentException(\n                    \"A context class must be a public non-abstract top-level or static nested class\");\n        }\n        Constructor<?> constructor = getConstructor(contextClazz);\n        if (constructor == null) {\n            throw new IllegalArgumentException(\n                    \"A context class must either declare a no-args constructor or a constructor that accepts a single parameter of type io.quarkus.arc.CurrentContextFactory\");\n        }\n        return creator(cg -> {\n            BlockCreator bc = cg.method();\n\n            List<Expr> args = constructor.getParameterCount() == 0 ? List.of() : List.of(cg.currentContextFactory());\n            return bc.new_(ConstructorDesc.of(constructor), args);\n        });\n    }\n\n    private Constructor<?> getConstructor(Class<? extends InjectableContext> contextClazz) {\n        Constructor<?> constructor = null;\n        try {\n            constructor = contextClazz.getDeclaredConstructor(CurrentContextFactory.class);\n        } catch (NoSuchMethodException ignored) {\n        }\n        if (constructor == null) {\n            try {","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ContextConfigurator.java#L103-L139","documentation":"Arc requires every custom context registered via ContextConfigurator.contextClass() to be instantiable from generated bytecode: it must have either a public no-arg constructor or one accepting a single io.quarkus.arc.CurrentContextFactory. If getConstructor() finds neither, an IllegalArgumentException is thrown at registration time.","triggerScenarios":"Registering a context class whose constructors take other parameter types (e.g. a String config argument) or whose no-arg constructor is private/not public.","commonSituations":"Porting a CDI context from another container that allowed constructor injection; making constructors package-private; adding a config parameter to the constructor after upgrading.","solutions":["Add a public no-args constructor to the context class","Or change the constructor to accept exactly one io.quarkus.arc.CurrentContextFactory parameter","If construction needs extra state, obtain it inside the context via the CurrentContextFactory or static config instead of constructor params"],"exampleFix":"// before\npublic MyContext(String name) { ... }\n// after\npublic MyContext() { ... }\n// or\npublic MyContext(io.quarkus.arc.CurrentContextFactory f) { ... }","handlingStrategy":"validation","validationCode":"static void validateContextCtor(Class<? extends InjectableContext> c) {\n  boolean ok = false;\n  for (Constructor<?> k : c.getConstructors()) {\n    if (k.getParameterCount() == 0) ok = true;\n    if (k.getParameterCount() == 1 && k.getParameterTypes()[0] == io.quarkus.arc.CurrentContextFactory.class) ok = true;\n  }\n  if (!ok) throw new IllegalArgumentException(\"No valid constructor on \" + c);\n}","typeGuard":"static boolean hasValidContextConstructor(Class<?> c) {\n  return java.util.Arrays.stream(c.getConstructors()).anyMatch(k ->\n      k.getParameterCount() == 0\n      || (k.getParameterCount() == 1 && k.getParameterTypes()[0] == io.quarkus.arc.CurrentContextFactory.class));\n}","tryCatchPattern":null,"preventionTips":["Provide a public no-arg constructor on every custom context","Use CurrentContextFactory parameter when you need contextual state storage"],"tags":["quarkus","arc","cdi","custom-context","constructor"],"backgroundTag":"invalid-custom-context-class","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}