spring-projects/spring-framework · warning · UnsupportedOperationException

No source location joinpoint available: target is null

Error message

No source location joinpoint available: target is null

What it means

Thrown by MethodInvocationProceedingJoinPoint's SourceLocationImpl.getWithinType() when the underlying target (methodInvocation.getThis()) is null. This happens when the advised object has no concrete target instance, e.g. when advising a static method or when the proxy uses a singleton target source that returned null.

Source

Thrown at spring-aop/src/main/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPoint.java:303

				appendType(sb, type.componentType(), useLongTypeName);
				sb.append("[]");
			}
			else {
				sb.append(useLongTypeName ? type.getName() : type.getSimpleName());
			}
		}
	}


	/**
	 * Lazily initialized SourceLocation.
	 */
	private class SourceLocationImpl implements SourceLocation {

		@Override
		public Class<?> getWithinType() {
			if (methodInvocation.getThis() == null) {
				throw new UnsupportedOperationException("No source location joinpoint available: target is null");
			}
			return methodInvocation.getThis().getClass();
		}

		@Override
		public String getFileName() {
			throw new UnsupportedOperationException();
		}

		@Override
		public int getLine() {
			throw new UnsupportedOperationException();
		}

		@Override
		@Deprecated(since = "4.0") // deprecated by AspectJ
		public int getColumn() {
			throw new UnsupportedOperationException();

View on GitHub (pinned to e8729d0438)

Solutions

  1. Avoid calling getSourceLocation().getWithinType() when the target may be null; guard with getTarget() != null first.
  2. Do not advise static methods expecting source location; Spring AOP is instance-based.
  3. Ensure the advised bean has a real target instance.

Example fix

// before
Class<?> within = pjp.getSourceLocation().getWithinType();

// after
Class<?> within = (pjp.getTarget() != null)
    ? pjp.getTarget().getClass()
    : pjp.getSignature().getDeclaringType();
Defensive patterns

Strategy: type-guard

Validate before calling

if (pjp.getTarget() == null) {
    // skip source location, fall back to signature declaring type
}

Type guard

boolean hasTarget = pjp.getTarget() != null;

Prevention

When it happens

Trigger: Calling JoinPoint.getSourceLocation().getWithinType() (directly or transitively) on an advice whose target is null — typically a static method advice or a scenario with no target object.

Common situations: Aspects that callgetSourceLocation() (uncommon); advising static methods via Spring AOP; CGLIB proxies on classes with no instance; misconfigured TargetSource returning null.

Related errors


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