spring-projects/spring-framework · error · UnsupportedOperationException

No source location joinpoint available: target is null

Error message

No source location joinpoint available: target is null

What it means

Thrown by SourceLocationImpl.getWithinType() when methodInvocation.getThis() (the target object) is null. This happens when the advised join point has no target instance, such as static method execution or when the proxy is backed by no underlying target bean (certain introduction or target-source scenarios).

Solutions

  1. Guard with a null check on getTarget() before calling getSourceLocation().getWithinType()
  2. Use getSignature().getDeclaringType() instead — it returns the declaring class without needing a target instance
  3. Restrict the pointcut to exclude static methods (use non-static execution matching or target() binding)

Example fix

// before
Class<?> type = joinPoint.getSourceLocation().getWithinType(); // throws if target null

// after
Object target = joinPoint.getTarget();
Class<?> type = (target != null)
    ? target.getClass()
    : joinPoint.getSignature().getDeclaringType();
Defensive patterns

Strategy: validation

Validate before calling

// Check for null target before calling getSourceLocation().getWithinType()
Object target = joinPoint.getTarget();
if (target == null) {
    // Static method or targetless proxy — use signature instead
    Class<?> declaringType = joinPoint.getSignature().getDeclaringType();
} else {
    Class<?> type = joinPoint.getSourceLocation().getWithinType();
}

Try / catch

try {
    Class<?> type = joinPoint.getSourceLocation().getWithinType();
} catch (UnsupportedOperationException ex) {
    // target is null — fall back to declaring type from signature
    Class<?> type = joinPoint.getSignature().getDeclaringType();
}

Prevention

When it happens

Trigger: An aspect calling joinPoint.getSourceLocation().getWithinType() on an advice that matched a static method, or on a proxy with a null target (e.g., via a TargetSource that returns null).

Common situations: Advice with a broad pointcut that inadvertently matches static methods, or programmatic interception of targetless proxies (e.g., empty target source for optimization).

Related errors


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

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