{"record":{"id":"4026b078bca3e41d","repo":"quarkusio/quarkus","slug":"the-given-type-is-a-type-variable-requiredtyp","errorCode":null,"errorMessage":"The given type is a type variable: \" + requiredType","messagePattern":"The given type is a type variable: \" \\+ requiredType","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ArcContainerImpl.java","lineNumber":608,"sourceCode":"\n    @SuppressWarnings(\"unchecked\")\n    private <T> InjectableBean<T> getBean(Type requiredType, Annotation... qualifiers) {\n        if (qualifiers == null || qualifiers.length == 0) {\n            qualifiers = new Annotation[] { Default.Literal.INSTANCE };\n        } else {\n            registeredQualifiers.verify(qualifiers);\n        }\n        Resolvable resolvable = new Resolvable(requiredType, qualifiers);\n        Set<InjectableBean<?>> resolvedBeans = resolved.getValue(resolvable);\n        if (resolvedBeans.isEmpty()) {\n            scanRemovedBeans(resolvable);\n        }\n        return resolvedBeans.size() != 1 ? null : (InjectableBean<T>) resolvedBeans.iterator().next();\n    }\n\n    Set<Bean<?>> getBeans(Type requiredType, Annotation... qualifiers) {\n        if (requiredType instanceof TypeVariable) {\n            throw new IllegalArgumentException(\"The given type is a type variable: \" + requiredType);\n        }\n        if (qualifiers == null || qualifiers.length == 0) {\n            qualifiers = new Annotation[] { Default.Literal.INSTANCE };\n        } else {\n            registeredQualifiers.verify(qualifiers);\n        }\n        // This method does not cache the results\n        return Set.of(getMatchingBeans(new Resolvable(requiredType, qualifiers)).toArray(new Bean<?>[] {}));\n    }\n\n    Set<Bean<?>> getBeans(String name) {\n        // This method does not cache the results\n        return new HashSet<>(getMatchingBeans(name));\n    }\n\n    boolean isScope(Class<? extends Annotation> annotationType) {\n        if (annotationType.isAnnotationPresent(Scope.class) || annotationType.isAnnotationPresent(NormalScope.class)) {\n            return true;","sourceCodeStart":590,"sourceCodeEnd":626,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ArcContainerImpl.java#L590-L626","documentation":"ArcContainerImpl.getBeans() rejects TypeVariable required types with IllegalArgumentException. The CDI spec requires the given type in BeanManager.getBeans() to be a concrete type; a type variable (e.g. T) carries no resolvable information. Arc fails fast instead of returning an empty/meaningless set.","triggerScenarios":"Calling beanManager.getBeans(someTypeVariable, qualifiers) or Arc.container().instance(...)/select(...) where the passed java.lang.reflect.Type is a TypeVariable instance, typically obtained from a generic method parameter or field.getGenericType() on a generic class.","commonSituations":"Writing generic helper/utility code that does programmatic lookup with T; reflection-based frameworks passing getGenericType() results; generifying a previously concrete lookup after a refactor.","solutions":["Pass the concrete resolved type (e.g. new ParameterizedType with actual type arguments, or the raw class) instead of the TypeVariable","Capture the generic type via an anonymous subclass (TypeLiteral<T>() {}) and pass its type","Add a runtime guard in your helper rejecting TypeVariable inputs before calling getBeans"],"exampleFix":"// before\n<T> void lookup() {\n    container.getBeans(/* T is a TypeVariable */ currentType);\n}\n\n// after\nType type = new TypeLiteral<List<String>>() {}.getType();\ncontainer.getBeans(type, Any.Literal.INSTANCE);","handlingStrategy":"validation","validationCode":"if (requiredType instanceof TypeVariable) {\n    throw new IllegalArgumentException(\"Resolve to a concrete type first: \" + requiredType);\n}\nSet<Bean<?>> beans = Arc.container().getBeans(requiredType, qualifiers);","typeGuard":"boolean isConcrete(Type t) {\n    return !(t instanceof TypeVariable)\n        && !(t instanceof WildcardType)\n        && !(t instanceof GenericArrayType);\n}","tryCatchPattern":"try {\n    beans = container.getBeans(type, quals);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"type variable\")) {\n        beans = container.getBeans(rawType(type), quals); // fallback to raw type\n    } else throw e;\n}","preventionTips":["Never pass raw generic method parameters (T) into bean lookup APIs","Use TypeLiteral/ParameterizedType anonymous subclasses to capture generic types","In generic helpers, require a Class<T> or Type argument instead of relying on T"],"tags":["cdi","generics","type-variable"],"backgroundTag":"illegal-type-variable","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"}