{"record":{"id":"6840006304c679a5","repo":"spring-projects/spring-framework","slug":"no-source-location-joinpoint-available-target-is","errorCode":null,"errorMessage":"No source location joinpoint available: target is null","messagePattern":"No source location joinpoint available: target is null","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPoint.java","lineNumber":303,"sourceCode":"\t\t\t\tappendType(sb, type.componentType(), useLongTypeName);\n\t\t\t\tsb.append(\"[]\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tsb.append(useLongTypeName ? type.getName() : type.getSimpleName());\n\t\t\t}\n\t\t}\n\t}\n\n\n\t/**\n\t * Lazily initialized SourceLocation.\n\t */\n\tprivate class SourceLocationImpl implements SourceLocation {\n\n\t\t@Override\n\t\tpublic Class<?> getWithinType() {\n\t\t\tif (methodInvocation.getThis() == null) {\n\t\t\t\tthrow new UnsupportedOperationException(\"No source location joinpoint available: target is null\");\n\t\t\t}\n\t\t\treturn methodInvocation.getThis().getClass();\n\t\t}\n\n\t\t@Override\n\t\tpublic String getFileName() {\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic int getLine() {\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\t@Deprecated(since = \"4.0\") // deprecated by AspectJ\n\t\tpublic int getColumn() {\n\t\t\tthrow new UnsupportedOperationException();","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPoint.java#L285-L321","documentation":"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).","triggerScenarios":"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).","commonSituations":"Advice with a broad pointcut that inadvertently matches static methods, or programmatic interception of targetless proxies (e.g., empty target source for optimization).","solutions":["Guard with a null check on getTarget() before calling getSourceLocation().getWithinType()","Use getSignature().getDeclaringType() instead — it returns the declaring class without needing a target instance","Restrict the pointcut to exclude static methods (use non-static execution matching or target() binding)"],"exampleFix":"// before\nClass<?> type = joinPoint.getSourceLocation().getWithinType(); // throws if target null\n\n// after\nObject target = joinPoint.getTarget();\nClass<?> type = (target != null)\n    ? target.getClass()\n    : joinPoint.getSignature().getDeclaringType();","handlingStrategy":"validation","validationCode":"// Check for null target before calling getSourceLocation().getWithinType()\nObject target = joinPoint.getTarget();\nif (target == null) {\n    // Static method or targetless proxy — use signature instead\n    Class<?> declaringType = joinPoint.getSignature().getDeclaringType();\n} else {\n    Class<?> type = joinPoint.getSourceLocation().getWithinType();\n}","typeGuard":null,"tryCatchPattern":"try {\n    Class<?> type = joinPoint.getSourceLocation().getWithinType();\n} catch (UnsupportedOperationException ex) {\n    // target is null — fall back to declaring type from signature\n    Class<?> type = joinPoint.getSignature().getDeclaringType();\n}","preventionTips":["Always null-check getTarget() before getSourceLocation().getWithinType()","Prefer getSignature().getDeclaringType() when you only need the class, as it never depends on a target instance","Restrict pointcuts to instance methods if the advice relies on target/source location"],"tags":["spring-aop","aspectj","source-location","null-target"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}