{"id":"8bbf33fbc91329be","repo":"spring-projects/spring-framework","slug":"spring-aop-cannot-handle-constructor-advice","errorCode":null,"errorMessage":"Spring AOP cannot handle constructor advice","messagePattern":"Spring AOP cannot handle constructor advice","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java","lineNumber":267,"sourceCode":"\t\t\t\treturn null;\n\t\t\t}\n\t\t\tStringTokenizer nameTokens = new StringTokenizer(annotation.getArgumentNames(), \",\");\n\t\t\tint numTokens = nameTokens.countTokens();\n\t\t\tif (numTokens > 0) {\n\t\t\t\tString[] names = new String[numTokens];\n\t\t\t\tfor (int i = 0; i < names.length; i++) {\n\t\t\t\t\tnames[i] = nameTokens.nextToken();\n\t\t\t\t}\n\t\t\t\treturn names;\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\n\t\t@Override\n\t\tpublic @Nullable String @Nullable [] getParameterNames(Constructor<?> ctor) {\n\t\t\tthrow new UnsupportedOperationException(\"Spring AOP cannot handle constructor advice\");\n\t\t}\n\t}\n\n}\n","sourceCodeStart":249,"sourceCodeEnd":272,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java#L249-L272","documentation":"Thrown by the AspectJAnnotationParameterNameDiscoverer when asked to resolve parameter names for a Constructor (not a Method). Spring AOP only advises methods on proxied beans; it never weaves constructor execution, so constructor advice is unsupported. This is a hard guard: any attempt to discover constructor parameter names in the AOP pipeline is rejected.","triggerScenarios":"An internal/extension code path that calls parameterNameDiscoverer.getParameterNames(Constructor) on the AspectJAnnotationParameterNameDiscoverer instance held by AbstractAspectJAdvisorFactory. Not reachable through normal @AspectJ advice processing.","commonSituations":"Custom subclasses or framework integrations that attempt to apply the AOP parameter discoverer to constructors. Essentially a programmer error in extending Spring AOP internals.","solutions":["Do not route constructor parameter discovery through Spring AOP's AspectJAnnotationParameterNameDiscoverer; use a standard ParameterNameDiscoverer instead.","If you need constructor interception, use AspectJ compile-time/load-time weaving, not Spring AOP."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Ensure you never pass a Constructor to the AOP parameter discoverer.\nif (member instanceof Constructor<?> c) {\n  throw new IllegalArgumentException(\"Constructor advice not supported; use a Method\");\n}","typeGuard":"boolean isMethodAdvice(java.lang.reflect.Member m) {\n  return m instanceof java.lang.reflect.Method;\n}","tryCatchPattern":null,"preventionTips":["Do not extend AbstractAspectJAdvisorFactory's parameter discoverer for constructor use.","Use AspectJ weaving for constructor interception."],"tags":["spring-aop","aspectj","constructor","unsupported"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}