{"record":{"id":"03d415ba199450ea","repo":"quarkusio/quarkus","slug":"initializer-method-may-not-be-generic-declare-typ","errorCode":null,"errorMessage":"Initializer method may not be generic (declare type parameters): ","messagePattern":"Initializer method may not be generic \\(declare type parameters\\): ","errorType":"validation","errorClass":"DefinitionException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java","lineNumber":338,"sourceCode":"            InjectionPointModifier transformer, boolean skipConstructors, Set<MethodOverrideKey> seenMethods) {\n\n        List<Injection> injections = new ArrayList<>();\n\n        List<AnnotationInstance> injectAnnotations = getAllInjectionPoints(beanDeployment, classInfo, DotNames.INJECT,\n                skipConstructors, seenMethods);\n\n        for (AnnotationInstance injectAnnotation : injectAnnotations) {\n            AnnotationTarget injectTarget = injectAnnotation.target();\n            switch (injectAnnotation.target().kind()) {\n                case FIELD:\n                    injections.add(new Injection(injectTarget, Collections.singletonList(\n                            InjectionPointInfo.fromField(injectTarget.asField(), beanClass, beanDeployment, transformer))));\n                    break;\n                case METHOD:\n                    // the spec doesn't forbid generic bean constructors and Weld is fine with them too\n                    if (!injectTarget.asMethod().isConstructor()\n                            && !injectTarget.asMethod().typeParameters().isEmpty()) {\n                        throw new DefinitionException(\n                                \"Initializer method may not be generic (declare type parameters): \" + injectTarget);\n                    }\n\n                    injections.add(new Injection(injectTarget,\n                            InjectionPointInfo.fromMethod(injectTarget.asMethod(), beanClass, beanDeployment, transformer)));\n                    break;\n                default:\n                    LOGGER.warn(\"Unsupported @Inject target ignored: \" + injectAnnotation.target());\n                    continue;\n            }\n        }\n        // if the class has no no-arg constructor and has a single non no-arg constructor that is not annotated with @Inject,\n        // the class is not a non-static inner or a superclass of a bean we consider that constructor as an injection\n        if (beanClass.equals(classInfo)) {\n            final boolean isNonStaticInnerClass = classInfo.name().isInner()\n                    && !Modifier.isStatic(classInfo.flags());\n            if (!isNonStaticInnerClass && !hasConstructorInjection(injections) && !beanClass.hasNoArgsConstructor()) {\n                List<MethodInfo> nonNoargConstrs = new ArrayList<>();","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java#L320-L356","documentation":"ArC forbids initializer/injector methods (non-constructor methods used for injection) from declaring type parameters. Generic constructors are allowed, but a generic initializer method cannot be resolved at bean creation. This is a CDI spec definition rule enforced at build time.","triggerScenarios":"Declaring an @Inject-annotated (or bean-defining) non-constructor method with type parameters, e.g. <T> void init(T x); found while building injections for a class bean via Injection.forClassBean.","commonSituations":"Adding generics to an existing @Inject setter for type-safety; refactoring a utility-style generic method into a bean initializer; migrating code where Weld previously surfaced a similar error.","solutions":["Remove the type parameters from the initializer method and use concrete types","Move the generic logic into a plain helper method called from the initializer","Inject via constructor instead, since generic constructors are permitted"],"exampleFix":"// before\n@Inject\n<T> void init(T value) {}\n// after\n@Inject\nvoid init(String value) {}","handlingStrategy":"validation","validationCode":"for (Method m : MyBean.class.getDeclaredMethods()) {\n    if (m.isAnnotationPresent(Inject.class) && m.getTypeParameters().length > 0) {\n        throw new IllegalStateException(\"Generic initializer: \" + m);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never add <T> type parameters to @Inject methods","Use concrete types in initializer signatures","Prefer constructor injection, which may be generic"],"tags":["cdi","arc","initializer","generics"],"backgroundTag":"generic-initializer-method","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"}