spring-projects/spring-framework · error · UnsupportedOperationException

Unsupported advice type on method: {}

Error message

Unsupported advice type on method: {}

What it means

Thrown by ReflectiveAspectJAdvisorFactory.getAdvice() in the default branch of the switch over AspectJAnnotationType. Because findAspectJAnnotationOnMethod only returns a non-null AspectJAnnotation for the six known types (AtPointcut, AtAround, AtBefore, AtAfter, AtAfterReturning, AtAfterThrowing), all of which have explicit cases, this branch is effectively unreachable under normal operation. Reaching it indicates an internal inconsistency in the annotation-type mapping.

Source

Thrown at spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java:297

			case AtAfter -> springAdvice = new AspectJAfterAdvice(
					candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
			case AtAfterReturning -> {
				springAdvice = new AspectJAfterReturningAdvice(
						candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
				AfterReturning afterReturningAnnotation = (AfterReturning) aspectJAnnotation.getAnnotation();
				if (StringUtils.hasText(afterReturningAnnotation.returning())) {
					springAdvice.setReturningName(afterReturningAnnotation.returning());
				}
			}
			case AtAfterThrowing -> {
				springAdvice = new AspectJAfterThrowingAdvice(
						candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
				AfterThrowing afterThrowingAnnotation = (AfterThrowing) aspectJAnnotation.getAnnotation();
				if (StringUtils.hasText(afterThrowingAnnotation.throwing())) {
					springAdvice.setThrowingName(afterThrowingAnnotation.throwing());
				}
			}
			default -> throw new UnsupportedOperationException(
					"Unsupported advice type on method: " + candidateAdviceMethod);
		}

		// Now to configure the advice...
		springAdvice.setAspectName(aspectName);
		springAdvice.setDeclarationOrder(declarationOrder);
		@Nullable String[] argNames = this.parameterNameDiscoverer.getParameterNames(candidateAdviceMethod);
		if (argNames != null) {
			springAdvice.setArgumentNamesFromStringArray(argNames);
		}
		springAdvice.calculateArgumentBindings();

		return springAdvice;
	}


	/**
	 * Synthetic advisor that instantiates the aspect.

View on GitHub (pinned to e8729d0438)

Solutions

  1. Verify spring-aop and aspectjweaver versions are matched and unmodified.
  2. If forking Spring, add a switch case for every new AspectJAnnotationType value.
  3. Report as a Spring Framework bug with the full stack trace.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  factory.getAdvice(method, pointcut, instanceFactory, order, name);
} catch (UnsupportedOperationException ex) {
  if (ex.getMessage().startsWith("Unsupported advice type")) {
    // internal inconsistency — check spring-aop / aspectjweaver versions
    throw new IllegalStateException("Possible Spring/AspectJ version mismatch", ex);
  }
  throw ex;
}

Prevention

When it happens

Trigger: Not reachable through public API in an unmodified Spring distribution. Would require a mismatch between ASPECTJ_ANNOTATION_CLASSES and the AspectJAnnotationType enum / switch cases (e.g. a fork adding a new annotation type without a switch case).

Common situations: Not encountered in standard use. Theoretically a fork/extension problem. Could appear with a corrupted aspectjweaver that misreports annotation types.

Related errors


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