{"id":"7f319d709521eb64","repo":"spring-projects/spring-framework","slug":"is-not-a-valid-aspectj-annotation","errorCode":null,"errorMessage":"{} is not a valid AspectJ annotation","messagePattern":"(.+?) is not a valid AspectJ annotation","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java","lineNumber":189,"sourceCode":"\n\t\tprivate final Annotation annotation;\n\n\t\tprivate final AspectJAnnotationType annotationType;\n\n\t\tprivate final String pointcutExpression;\n\n\t\tprivate final String argumentNames;\n\n\t\tpublic AspectJAnnotation(Annotation annotation) {\n\t\t\tthis.annotation = annotation;\n\t\t\tthis.annotationType = determineAnnotationType(annotation);\n\t\t\ttry {\n\t\t\t\tthis.pointcutExpression = resolvePointcutExpression(annotation);\n\t\t\t\tObject argNames = AnnotationUtils.getValue(annotation, \"argNames\");\n\t\t\t\tthis.argumentNames = (argNames instanceof String names ? names : \"\");\n\t\t\t}\n\t\t\tcatch (Exception ex) {\n\t\t\t\tthrow new IllegalArgumentException(annotation + \" is not a valid AspectJ annotation\", ex);\n\t\t\t}\n\t\t}\n\n\t\tprivate AspectJAnnotationType determineAnnotationType(Annotation annotation) {\n\t\t\tAspectJAnnotationType type = annotationTypeMap.get(annotation.annotationType());\n\t\t\tif (type != null) {\n\t\t\t\treturn type;\n\t\t\t}\n\t\t\tthrow new IllegalStateException(\"Unknown annotation type: \" + annotation);\n\t\t}\n\n\t\tprivate String resolvePointcutExpression(Annotation annotation) {\n\t\t\tfor (String attributeName : EXPRESSION_ATTRIBUTES) {\n\t\t\t\tObject val = AnnotationUtils.getValue(annotation, attributeName);\n\t\t\t\tif (val instanceof String str && !str.isEmpty()) {\n\t\t\t\t\treturn str;\n\t\t\t\t}\n\t\t\t}","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java#L171-L207","documentation":"Thrown inside the AspectJAnnotation constructor when resolving the pointcut expression or argNames from a method-level AspectJ annotation (@Before, @Around, @After, @AfterReturning, @AfterThrowing, @Pointcut) fails. It wraps the underlying reflective exception, signalling that the annotation is malformed or its attributes cannot be read. This is generally a low-level parsing failure indicating annotation attributes are missing or in an unexpected state.","triggerScenarios":"ReflectiveAspectJAdvisorFactory.getAdvice()/getAdvisor() calling findAspectJAnnotationOnMethod on a method whose AspectJ annotation has attributes that AnnotationUtils.getValue cannot read correctly, or where the annotation proxy throws on access.","commonSituations":"A corrupted or partially applied annotation, a custom meta-annotation masquerading as an AspectJ advice annotation, classpath/version conflicts in aspectjweaver that break annotation proxies, or reflective manipulation of aspects.","solutions":["Inspect the offending annotation on the named method: ensure it is a genuine AspectJ annotation with a valid String 'value' or 'pointcut' attribute.","Verify aspectjweaver and spring-aop versions are aligned and present on the classpath.","Recompile the aspect class to eliminate stale or corrupted annotation metadata.","If using meta-annotations, ensure the pointcut expression attribute is resolvable via Spring's AnnotationUtils."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import org.springframework.core.annotation.AnnotationUtils;\nimport org.aspectj.lang.annotation.*;\nimport java.lang.reflect.Method;\n\nvoid verifyAdviceAnnotationReadable(Method m) {\n  for (Class<?> a : new Class<?>[]{Before.class, Around.class, After.class,\n          AfterReturning.class, AfterThrowing.class, Pointcut.class}) {\n    Object ann = AnnotationUtils.findAnnotation(m, a);\n    if (ann != null) {\n      Object v = AnnotationUtils.getValue(ann, \"value\");\n      Object p = AnnotationUtils.getValue(ann, \"pointcut\");\n      if (!(v instanceof String s && !s.isEmpty()) && !(p instanceof String s2 && !s2.isEmpty()))\n        throw new IllegalStateException(\"Advice annotation on \" + m + \" has no readable pointcut\");\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  factory.getAdvisors(instanceFactory);\n} catch (IllegalArgumentException ex) {\n  if (ex.getMessage().contains(\"not a valid AspectJ annotation\")) {\n    log.error(\"Malformed advice annotation on aspect method\", ex);\n  } else throw ex;\n}","preventionTips":["Keep aspectjweaver and spring-aop versions aligned on the classpath.","Avoid meta-annotation tricks over AspectJ advice annotations.","Recompile aspect classes after editing annotations."],"tags":["spring-aop","aspectj","annotation","reflection"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}