{"record":{"id":"a289bd3ae09a72bd","repo":"quarkusio/quarkus","slug":"event-select-class-u-annotation-cannot-be-us","errorCode":null,"errorMessage":"Event#select(Class<U>, Annotation...) cannot be used with type variable parameter","messagePattern":"Event#select\\(Class<U>, Annotation\\.\\.\\.\\) cannot be used with type variable parameter","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/EventImpl.java","lineNumber":147,"sourceCode":"                    @Override\n                    public Notifier<? super T> apply(Class<?> clazz) {\n                        return createNotifier(clazz);\n                    }\n                });\n    }\n\n    @Override\n    public Event<T> select(Annotation... qualifiers) {\n        ArcContainerImpl.instance().registeredQualifiers.verify(qualifiers);\n        Set<Annotation> mergedQualifiers = new HashSet<>(this.qualifiers);\n        Collections.addAll(mergedQualifiers, qualifiers);\n        return new EventImpl<T>(eventType, mergedQualifiers, injectionPoint);\n    }\n\n    @Override\n    public <U extends T> Event<U> select(Class<U> subtype, Annotation... qualifiers) {\n        if (Types.containsTypeVariable(subtype)) {\n            throw new IllegalArgumentException(\n                    \"Event#select(Class<U>, Annotation...) cannot be used with type variable parameter\");\n        }\n        ArcContainerImpl.instance().registeredQualifiers.verify(qualifiers);\n        Set<Annotation> mergerdQualifiers = new HashSet<>(this.qualifiers);\n        Collections.addAll(mergerdQualifiers, qualifiers);\n        return new EventImpl<U>(subtype, mergerdQualifiers, injectionPoint);\n    }\n\n    @Override\n    public <U extends T> Event<U> select(TypeLiteral<U> subtype, Annotation... qualifiers) {\n        ArcContainerImpl.instance().registeredQualifiers.verify(qualifiers);\n        if (Types.containsTypeVariable(subtype.getType())) {\n            throw new IllegalArgumentException(\n                    \"Event#select(TypeLiteral, Annotation...) cannot be used with type variable parameter\");\n        }\n        Set<Annotation> mergerdQualifiers = new HashSet<>(this.qualifiers);\n        Collections.addAll(mergerdQualifiers, qualifiers);\n        return new EventImpl<U>(subtype.getType(), mergerdQualifiers, injectionPoint);","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/EventImpl.java#L129-L165","documentation":"EventImpl.select(Class<U>, Annotation...) — the CDI Event#select API — rejects a subtype parameter that still contains type variables (e.g. Class<T> where T is a generic type parameter of the enclosing method/class). The CDI spec forbids selecting on unresolved type variables because the resulting event type could not be resolved at runtime, so ArC throws IllegalArgumentException.","triggerScenarios":"Inside a generic class/method, calling event.select(SomeGenericClass.class) where SomeGenericClass is itself generic and the class literal (e.g. T.class or ResultWrapper.class with T unresolved) contains type variables; the other select(TypeLiteral) overload throws its own analogous error.","commonSituations":"Generic helper/service classes wrapping CDI events where developers pass Class<T> fields obtained from generic APIs; refactoring an event publisher into a generic base class; Java's type erasure making Class<T> literals retain unresolved type variables.","solutions":["Use the concrete, non-generic class literal in select(), or reify the generic type with a TypeLiteral: event.select(new TypeLiteral<List<String>>() {}).","Pass the runtime class via a constructor/parameter captured from the concrete subclass (getClass() at a non-generic call site).","Move the select() call to a non-generic location where the type is fully known.","If full runtime generic info is needed, use super type tokens (subclass anonymous TypeLiteral) rather than Class<T>."],"exampleFix":"// before\nclass Publisher<T> {\n  void fire(T payload) { event.select((Class<T>) payload.getClass()); } // may still contain type vars\n}\n\n// after\nevent.select(new TypeLiteral<MyConcretePayload>() {});","handlingStrategy":"type-guard","validationCode":"if (Types.containsTypeVariable(subtype)) {\n    throw new IllegalArgumentException(\"select() requires a fully resolved type, got \" + subtype);\n}","typeGuard":"static <T> boolean isConcreteEventType(Class<T> subtype) {\n    return !io.quarkus.arc.impl.Types.containsTypeVariable(subtype);\n}","tryCatchPattern":"try {\n    event.select(subtypeClass);\n} catch (IllegalArgumentException e) {\n    if (!e.getMessage().contains(\"type variable parameter\")) throw e;\n    // fall back to a TypeLiteral-based select with a resolved type\n}","preventionTips":["Prefer TypeLiteral (super type token) over Class<T> when selecting generic event subtypes.","Avoid calling Event.select from generic classes/methods; resolve the type first.","Capture concrete classes at non-generic call sites (e.g. getClass() in concrete subclasses)."],"tags":["cdi","events","generics","type-variable","quarkus-arc"],"backgroundTag":"type-variable-not-allowed","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"}