{"record":{"id":"4896bc753d4cae32","repo":"quarkusio/quarkus","slug":"annotation-instance-annotationinstance-does-not","errorCode":null,"errorMessage":"Annotation instance ${annotationInstance} does not match annotation type ${annotationType.getName()}","messagePattern":"Annotation instance (.+?) does not match annotation type (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/deployment/src/main/java/io/quarkus/deployment/recording/AnnotationProxyProvider.java","lineNumber":59,"sourceCode":"    private final ClassLoader classLoader;\n    private final IndexView index;\n\n    AnnotationProxyProvider(IndexView index) {\n        this.annotationLiterals = new ConcurrentHashMap<>();\n        this.annotationClasses = new ConcurrentHashMap<>();\n        this.generatedLiterals = new ConcurrentHashMap<>();\n        this.index = index;\n        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();\n        if (classLoader == null) {\n            classLoader = AnnotationProxy.class.getClassLoader();\n        }\n        this.classLoader = classLoader;\n    }\n\n    public <A extends Annotation> AnnotationProxyBuilder<A> builder(AnnotationInstance annotationInstance,\n            Class<A> annotationType) {\n        if (!annotationInstance.name().toString().equals(annotationType.getName())) {\n            throw new IllegalArgumentException(\"Annotation instance \" + annotationInstance + \" does not match annotation type \"\n                    + annotationType.getName());\n        }\n        ClassInfo annotationClass = annotationClasses.computeIfAbsent(annotationInstance.name(), name -> {\n            ClassInfo clazz = index.getClassByName(name);\n            if (clazz == null) {\n                try (InputStream annotationStream = IoUtil.readClass(classLoader, name.toString())) {\n                    clazz = Index.singleClass(annotationStream);\n                } catch (Exception e) {\n                    throw new IllegalStateException(\"Failed to index: \" + name, e);\n                }\n            }\n            return clazz;\n        });\n        String annotationLiteral = annotationLiterals.computeIfAbsent(annotationInstance.name(),\n                // com.foo.MyAnnotation -> com.foo.MyAnnotation_Proxy_AnnotationLiteral\n                name -> name + \"_Proxy_AnnotationLiteral\");\n\n        return new AnnotationProxyBuilder<>(annotationInstance, annotationType, annotationLiteral, annotationClass);","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/core/deployment/src/main/java/io/quarkus/deployment/recording/AnnotationProxyProvider.java#L41-L77","documentation":"AnnotationProxyProvider.builder() creates runtime annotation literals from Jandex AnnotationInstance data. It validates that the instance's annotation name equals the requested annotation type's binary name; a mismatch means the caller passed an instance of a different annotation than the literal is being built for, which would produce a wrongly-typed proxy.","triggerScenarios":"Calling AnnotationProxyProvider.builder(annotationInstance, SomeAnnotation.class) where annotationInstance.name() does not equal SomeAnnotation's fully qualified name — typically a lookup-by-name/predicate returned instances of other annotations mixed in with the target.","commonSituations":"Build steps scanning all annotations of a class and passing them to the proxy provider without filtering by name; iterating a Jandex index with a loose name prefix match.","solutions":["Filter AnnotationInstances by exact name before calling builder(): instance.name().toString().equals(AnnotationType.class.getName())","Use index.getAnnotations(DotName.createSimple(AnnotationType.class.getName())) to fetch only matching instances","Check for duplicate/wrong imports of the annotation class (same simple name, different package)"],"exampleFix":"// before\nfor (AnnotationInstance ai : classInfo.annotations()) {\n    builder(ai, MyAnno.class); // may pass foreign annotations\n}\n// after\nfor (AnnotationInstance ai : classInfo.annotations(DotName.createSimple(MyAnno.class.getName()))) {\n    builder(ai, MyAnno.class);\n}","handlingStrategy":"validation","validationCode":"if (!ai.name().toString().equals(MyAnno.class.getName())) {\n    throw new IllegalArgumentException(\"wrong annotation: \" + ai.name());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fetch AnnotationInstances with exact DotName queries","Beware same-simple-name annotations from different packages","Assert instance.name() matches the target type in custom build steps"],"tags":["jandex","annotation","build-time","recording"],"backgroundTag":"annotation-type-mismatch","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"}