spring-projects/spring-framework · error · IllegalStateException

Unknown annotation type: {}

Error message

Unknown annotation type: {}

What it means

Thrown by AspectJAnnotation.determineAnnotationType() when the annotation instance's type is not one of the six known AspectJ advice/pointcut annotations (Pointcut, Around, Before, After, AfterReturning, AfterThrowing). Because findAspectJAnnotationOnMethod only constructs AspectJAnnotation for annotations of those exact types, reaching this branch indicates an internal inconsistency — the annotation type map lacks an entry for a type that slipped through.

Source

Thrown at spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java:198

		public AspectJAnnotation(Annotation annotation) {
			this.annotation = annotation;
			this.annotationType = determineAnnotationType(annotation);
			try {
				this.pointcutExpression = resolvePointcutExpression(annotation);
				Object argNames = AnnotationUtils.getValue(annotation, "argNames");
				this.argumentNames = (argNames instanceof String names ? names : "");
			}
			catch (Exception ex) {
				throw new IllegalArgumentException(annotation + " is not a valid AspectJ annotation", ex);
			}
		}

		private AspectJAnnotationType determineAnnotationType(Annotation annotation) {
			AspectJAnnotationType type = annotationTypeMap.get(annotation.annotationType());
			if (type != null) {
				return type;
			}
			throw new IllegalStateException("Unknown annotation type: " + annotation);
		}

		private String resolvePointcutExpression(Annotation annotation) {
			for (String attributeName : EXPRESSION_ATTRIBUTES) {
				Object val = AnnotationUtils.getValue(annotation, attributeName);
				if (val instanceof String str && !str.isEmpty()) {
					return str;
				}
			}
			throw new IllegalStateException("Failed to resolve pointcut expression in: " + annotation);
		}

		public AspectJAnnotationType getAnnotationType() {
			return this.annotationType;
		}

		public Annotation getAnnotation() {
			return this.annotation;

View on GitHub (pinned to e8729d0438)

Solutions

  1. Verify you are using an unmodified, version-matched spring-aop and aspectjweaver pair.
  2. If forking Spring, ensure annotationTypeMap has an entry for every class in ASPECTJ_ANNOTATION_CLASSES.
  3. File a Spring Framework bug with the full stack trace and annotation details.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  factory.getAdvisors(instanceFactory);
} catch (IllegalStateException ex) {
  if (ex.getMessage().startsWith("Unknown annotation type")) {
    // internal inconsistency — report spring-aop / aspectjweaver version mismatch
    throw new IllegalStateException("Spring/AspectJ version mismatch detected", ex);
  }
  throw ex;
}

Prevention

When it happens

Trigger: This is effectively an internal/unreachable error: findAspectJAnnotationOnMethod iterates only over ASPECTJ_ANNOTATION_CLASSES, so annotationTypeMap should always contain a mapping. It would only fire if the map was extended or the annotation lookup returned a wrapper/meta-annotation not in the map.

Common situations: Not encountered under normal use. Theoretically reachable via a forked Spring version that adds an annotation to ASPECTJ_ANNOTATION_CLASSES without updating annotationTypeMap, or via a corrupted aspectjweaver.

Related errors


AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04). Data as JSON: /data/errors/49e09a803fa47c33.json. Report an issue: GitHub.