{"record":{"id":"4ac8f69439877101","repo":"quarkusio/quarkus","slug":"unable-to-instantiate-the-class","errorCode":null,"errorMessage":"Unable to instantiate the class: ","messagePattern":"Unable to instantiate the class: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/scheduler/common/src/main/java/io/quarkus/scheduler/common/runtime/util/SchedulerUtils.java","lineNumber":124,"sourceCode":"\n    public static boolean isConfigValue(String val) {\n        return isSimpleConfigValue(val) || isConfigExpression(val);\n    }\n\n    public static ZoneId parseCronTimeZone(Scheduled scheduled) {\n        String timeZone = lookUpPropertyValue(scheduled.timeZone());\n        return timeZone.equals(Scheduled.DEFAULT_TIMEZONE) ? null : ZoneId.of(timeZone);\n    }\n\n    public static <T> T instantiateBeanOrClass(Class<T> type) {\n        Instance<T> instance = Arc.container().select(type, Any.Literal.INSTANCE);\n        if (instance.isAmbiguous()) {\n            throw new IllegalArgumentException(\"Multiple beans match the type: \" + type);\n        } else if (instance.isUnsatisfied()) {\n            try {\n                return type.getConstructor().newInstance();\n            } catch (Exception e) {\n                throw new IllegalStateException(\"Unable to instantiate the class: \" + type);\n            }\n        } else {\n            return instance.get();\n        }\n    }\n\n    private static boolean isSimpleConfigValue(String val) {\n        val = val.trim();\n        return val.startsWith(\"{\") && val.endsWith(\"}\");\n    }\n\n    /**\n     * Converts \"{property}\" to \"${property}\" for backwards compatibility\n     */\n    private static String adjustExpressionSyntax(String val) {\n        if (isSimpleConfigValue(val)) {\n            return '$' + val;\n        }","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/scheduler/common/src/main/java/io/quarkus/scheduler/common/runtime/util/SchedulerUtils.java#L106-L142","documentation":"SchedulerUtils needs an instance of the @Scheduled business class. It first tries CDI bean lookup; if no bean matches (unsatisfied), it falls back to calling the public no-arg constructor via reflection. This IllegalStateException wraps any failure of that reflective instantiation (missing no-arg constructor, constructor throwing, non-public constructor, abstract class).","triggerScenarios":"A class annotated with @Scheduled is not registered as a CDI bean (missing scope annotation) AND has no usable public no-argument constructor, or its constructor throws.","commonSituations":"Developer adds @Scheduled to a plain class without @ApplicationScoped/@Singleton; class has only constructor with parameters; constructor performs DI or IO that fails at build/startup; class is abstract or an inner non-static class.","solutions":["Add a CDI scope annotation (e.g. @ApplicationScoped or @Singleton) to the @Scheduled class so it is discovered as a bean","Ensure the class has a public no-argument constructor if it is intentionally not a bean","Make sure the constructor does not throw during instantiation","Avoid annotating abstract classes with instance-level @Scheduled methods"],"exampleFix":"// before\nclass Tasks {\n    Tasks(Service svc) { ... } // no no-arg ctor, not a bean\n    @Scheduled(every = \"10s\") void run() {}\n}\n// after\n@ApplicationScoped\nclass Tasks {\n    @Inject Service svc;\n    @Scheduled(every = \"10s\") void run() {}\n}","handlingStrategy":"validation","validationCode":"Class<?> c = Tasks.class;\nboolean ok = c.isAnnotationPresent(jakarta.inject.Scope.class)\n    || java.lang.reflect.Modifier.isAbstract(c.getModifiers()) == false\n        && java.util.Arrays.stream(c.getConstructors())\n            .anyMatch(ctor -> ctor.getParameterCount() == 0);","typeGuard":"static boolean isInstantiable(Class<?> c) {\n    return !c.isInterface() && !java.lang.reflect.Modifier.isAbstract(c.getModifiers())\n        && java.util.Arrays.stream(c.getConstructors())\n            .anyMatch(ctor -> java.lang.reflect.Modifier.isPublic(ctor.getModifiers())\n                && ctor.getParameterCount() == 0);\n}","tryCatchPattern":"try { new Tasks(); } catch (IllegalStateException e) {\n    // fall back: register as CDI bean or fix no-arg constructor\n}","preventionTips":["Always give @Scheduled classes a CDI scope annotation","Keep a public no-arg constructor on non-bean scheduled classes","Avoid heavy logic in constructors","Don't annotate abstract classes with instance-level scheduled methods"],"tags":["scheduler","cdi","reflection","quarkus"],"backgroundTag":"cdi-bean-not-found","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"}