{"record":{"id":"c3380b42be640483","repo":"spring-projects/spring-framework","slug":"unknown-annotation-type-annotation","errorCode":null,"errorMessage":"Unknown annotation type: {annotation}","messagePattern":"Unknown annotation type: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java","lineNumber":198,"sourceCode":"\t\tpublic AspectJAnnotation(Annotation annotation) {\n\t\t\tthis.annotation = annotation;\n\t\t\tthis.annotationType = determineAnnotationType(annotation);\n\t\t\ttry {\n\t\t\t\tthis.pointcutExpression = resolvePointcutExpression(annotation);\n\t\t\t\tObject argNames = AnnotationUtils.getValue(annotation, \"argNames\");\n\t\t\t\tthis.argumentNames = (argNames instanceof String names ? names : \"\");\n\t\t\t}\n\t\t\tcatch (Exception ex) {\n\t\t\t\tthrow new IllegalArgumentException(annotation + \" is not a valid AspectJ annotation\", ex);\n\t\t\t}\n\t\t}\n\n\t\tprivate AspectJAnnotationType determineAnnotationType(Annotation annotation) {\n\t\t\tAspectJAnnotationType type = annotationTypeMap.get(annotation.annotationType());\n\t\t\tif (type != null) {\n\t\t\t\treturn type;\n\t\t\t}\n\t\t\tthrow new IllegalStateException(\"Unknown annotation type: \" + annotation);\n\t\t}\n\n\t\tprivate String resolvePointcutExpression(Annotation annotation) {\n\t\t\tfor (String attributeName : EXPRESSION_ATTRIBUTES) {\n\t\t\t\tObject val = AnnotationUtils.getValue(annotation, attributeName);\n\t\t\t\tif (val instanceof String str && !str.isEmpty()) {\n\t\t\t\t\treturn str;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow new IllegalStateException(\"Failed to resolve pointcut expression in: \" + annotation);\n\t\t}\n\n\t\tpublic AspectJAnnotationType getAnnotationType() {\n\t\t\treturn this.annotationType;\n\t\t}\n\n\t\tpublic Annotation getAnnotation() {\n\t\t\treturn this.annotation;","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java#L180-L216","documentation":"Thrown as an IllegalStateException from AspectJAnnotation.determineAnnotationType() when the annotation's runtime class is not one of the six known AspectJ types in the annotationTypeMap (Pointcut, Around, Before, After, AfterReturning, AfterThrowing). Because findAspectJAnnotationOnMethod already restricts to exactly those six types, reaching this branch indicates an internal invariant violation rather than a normal user error.","triggerScenarios":"Construction of an AspectJAnnotation wrapper with an Annotation instance whose type is not in the known map (should not happen via the public factory path); a custom subclass that bypasses findAspectJAnnotationOnMethod and passes an arbitrary annotation into AspectJAnnotation; concurrent modification or a future AspectJ annotation type added without updating the map.","commonSituations":"Library/framework code that extends AbstractAspectJAdvisorFactory and instantiates AspectJAnnotation directly with a non-standard annotation; an AspectJ version mismatch introducing a new advice annotation not yet mapped by Spring; test code constructing AspectJAnnotation with a mock annotation.","solutions":["Do not instantiate AspectJAnnotation directly; rely on findAspectJAnnotationOnMethod which only accepts the six known annotation types.","If extending the framework, ensure you pass only the six recognized AspectJ annotation types.","Upgrade Spring to a version that maps the AspectJ annotation type you are using.","Report as a Spring bug if reached through normal API usage."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// This error is an internal invariant violation. Defense = do not construct AspectJAnnotation\n// with annotations outside the six known types. Prefer the public path:\nimport org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactory;\n\n// Use the factory's own discovery rather than constructing AspectJAnnotation directly:\n// AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(method) returns null for unknown types.\n","typeGuard":"import org.aspectj.lang.annotation.*;\nimport java.util.Set;\n\npublic static boolean isKnownAspectJAnnotationType(Class<? extends java.lang.annotation.Annotation> t) {\n    return Set.of(Pointcut.class, Around.class, Before.class, After.class,\n                  AfterReturning.class, AfterThrowing.class).contains(t);\n}","tryCatchPattern":"try {\n    List<Advisor> advisors = advisorFactory.getAdvisors(factory);\n} catch (IllegalStateException ex) {\n    if (ex.getMessage().startsWith(\"Unknown annotation type\")) {\n        // collect details and report to Spring; should be unreachable\n    } else throw ex;\n}","preventionTips":["Do not extend AbstractAspectJAdvisorFactory.AspectJAnnotation with non-standard annotation types.","Keep Spring and AspectJ versions compatible.","Treat 'Unknown annotation type' as a bug report, not a config error."],"tags":["spring-aop","aspectj","internal","annotations"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}