{"record":{"id":"83d026ab19e01b81","repo":"quarkusio/quarkus","slug":"creationexception-wrapping-original-cause-from-con","errorCode":null,"errorMessage":"CreationException wrapping original cause from constructor invocation failure","messagePattern":"CreationException wrapping original cause from constructor invocation failure","errorType":"exception","errorClass":"jakarta.enterprise.inject.CreationException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/Reflections.java","lineNumber":143,"sourceCode":"\n    public static Object newInstance(Class<?> clazz, Class<?>[] parameterTypes, Object[] args) {\n        Constructor<?> constructor = findConstructor(clazz, parameterTypes);\n        if (constructor != null) {\n            if (!constructor.canAccess(null)) {\n                constructor.setAccessible(true);\n            }\n            try {\n                return constructor.newInstance(args);\n            } catch (InvocationTargetException e) {\n                Throwable cause = e.getCause();\n                if (cause instanceof RuntimeException) {\n                    throw (RuntimeException) cause;\n                }\n                if (cause instanceof Error) {\n                    throw (Error) cause;\n                }\n                // this method is only used to instantiate beans, so throwing `CreationException` is fine\n                throw new CreationException(cause);\n            } catch (InstantiationException | IllegalAccessException | IllegalArgumentException e) {\n                throw new RuntimeException(\"Cannot invoke constructor: \" + clazz.getName(), e);\n            }\n        }\n        throw new RuntimeException(\n                \"No \" + clazz.getName() + \"constructor found for params: \" + Arrays.toString(parameterTypes));\n    }\n\n    public static Object readField(Class<?> clazz, String name, Object instance) {\n        try {\n            Field field = clazz.getDeclaredField(name);\n            if (!field.canAccess(instance)) {\n                field.setAccessible(true);\n            }\n            return field.get(instance);\n        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {\n            throw new RuntimeException(\"Cannot read field value: \" + clazz.getName() + \"#\" + name, e);\n        }","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/Reflections.java#L125-L161","documentation":"Reflections.newInstance() invokes a bean constructor reflectively. If the constructor itself throws, the original cause is unwrapped and rethrown: as RuntimeException, Error, or — since this is only used to instantiate beans — wrapped in a jakarta.enterprise.inject.CreationException. The message in the error record corresponds to that CreationException wrapping path.","triggerScenarios":"A bean constructor throws during container initialization (Arc.container().instance(...), @PostConstruct-time injection, programmatic lookup) — e.g. it throws NPE/IllegalStateException, and the container surfaces it as CreationException with the original cause.","commonSituations":"Constructor performs heavy logic that fails (missing config property, DB not up, null injection into constructor using field injection); missing dependency at runtime; environment misconfiguration (missing env var, wrong URL) surfacing at bean creation.","solutions":["Read getCause() of the CreationException — the root stack trace names the failing line in your constructor.","Keep constructors minimal: inject dependencies and defer work to @PostConstruct or first use.","Use constructor parameter injection instead of field injection so required values are available at construction.","Validate external prerequisites (config properties, connections) before/inside bean creation with clear failure messages."],"exampleFix":"// before\n@ApplicationScoped\nclass Repo { @Inject Config cfg; Repo() { connect(cfg.url()); } } // cfg null in constructor\n// after\n@ApplicationScoped\nclass Repo { private final Config cfg; Repo(Config cfg) { this.cfg = cfg; } \n  @PostConstruct void init() { connect(cfg.url()); } }","handlingStrategy":"try-catch","validationCode":"// pre-flight: resolve the bean early so constructor failures surface at startup\nArc.container().instance(MyBean.class).get();","typeGuard":null,"tryCatchPattern":"try {\n    MyBean bean = Arc.container().instance(MyBean.class).get();\n} catch (CreationException e) {\n    Throwable root = e.getCause();\n    log.error(\"Bean construction failed — root cause:\", root);\n    throw new IllegalStateException(\"Fix constructor logic/config: \" + root.getMessage(), root);\n}","preventionTips":["Keep constructors free of side effects and external calls","Use constructor injection, not field injection, for required collaborators","Defer initialization work to @PostConstruct or lazy first use","Fail fast with clear messages when config/env prerequisites are missing"],"tags":["cdi","bean-creation","arc","reflection"],"backgroundTag":"bean-creation-failed","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"}