spring-projects/spring-framework · error · UnsupportedOperationException

Unsupported advice type on method: {candidateAdviceMethod}

Error message

Unsupported advice type on method: {candidateAdviceMethod}

What it means

Thrown as an UnsupportedOperationException from ReflectiveAspectJAdvisorFactory.getAdvice() in the switch default branch when the AspectJAnnotation's type is not AtPointcut, AtAround, AtBefore, AtAfter, AtAfterReturning, or AtAfterThrowing. Because findAspectJAnnotationOnMethod only produces annotations of those six types and AtPointcut returns null earlier, reaching this default is effectively unreachable through normal API usage, indicating an internal/state corruption.

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 69bf83ad71)

Solutions

  1. If encountered, collect the aspectJAdviceMethod and aspectJAnnotation details and report it as a Spring bug (it should be unreachable).
  2. Ensure you are using mutually compatible versions of Spring AOP and AspectJ.
  3. Avoid reflecting into or constructing AspectJAnnotation with non-standard types.
Defensive patterns

Strategy: try-catch

Validate before calling

// Unreachable via normal API; defense = keep Spring AOP and AspectJ versions compatible and
// do not construct AspectJAnnotation with non-standard types.
import org.aspectj.lang.annotation.*;
import java.util.Set;

public static boolean isSwitchHandledAdviceAnnotation(Class<? extends java.lang.annotation.Annotation> t) {
    return Set.of(Around.class, Before.class, After.class,
                  AfterReturning.class, AfterThrowing.class).contains(t); // AtPointcut returns null earlier
}

Try / catch

try {
    Advice advice = advisorFactory.getAdvice(method, pointcut, factory, order, name);
} catch (UnsupportedOperationException ex) {
    if (ex.getMessage().startsWith("Unsupported advice type")) {
        // should be unreachable; capture method + annotation and report upstream
    } else throw ex;
}

Prevention

When it happens

Trigger: Internal: the AspectJAnnotation was constructed with a type not present in the switch; a future AspectJ annotation type added without updating the switch; reflective/test manipulation of the AspectJAnnotation type field. Not reachable via standard Spring AOP configuration.

Common situations: Library extensions that tamper with AspectJAnnotation; an AspectJ/Spring version skew introducing a new advice annotation type; corrupted/advisory state in tests.

Related errors


AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09). Data as JSON: /api/errors/679bbfea68709ff1. Report an issue: GitHub.