{"id":"9909b57e840d5df3","repo":"spring-projects/spring-framework","slug":"defaultimpl-attribute-must-be-set-on-declarepare","errorCode":null,"errorMessage":"'defaultImpl' attribute must be set on DeclareParents","messagePattern":"'defaultImpl' attribute must be set on DeclareParents","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java","lineNumber":192,"sourceCode":"\t\treturn methods;\n\t}\n\n\t/**\n\t * Build a {@link org.springframework.aop.aspectj.DeclareParentsAdvisor}\n\t * for the given introduction field.\n\t * <p>Resulting Advisors will need to be evaluated for targets.\n\t * @param introductionField the field to introspect\n\t * @return the Advisor instance, or {@code null} if not an Advisor\n\t */\n\tprivate @Nullable Advisor getDeclareParentsAdvisor(Field introductionField) {\n\t\tDeclareParents declareParents = introductionField.getAnnotation(DeclareParents.class);\n\t\tif (declareParents == null) {\n\t\t\t// Not an introduction field\n\t\t\treturn null;\n\t\t}\n\n\t\tif (DeclareParents.class == declareParents.defaultImpl()) {\n\t\t\tthrow new IllegalStateException(\"'defaultImpl' attribute must be set on DeclareParents\");\n\t\t}\n\n\t\treturn new DeclareParentsAdvisor(\n\t\t\t\tintroductionField.getType(), declareParents.value(), declareParents.defaultImpl());\n\t}\n\n\n\t@Override\n\tpublic @Nullable Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aspectInstanceFactory,\n\t\t\tint declarationOrderInAspect, String aspectName) {\n\n\t\tvalidate(aspectInstanceFactory.getAspectMetadata().getAspectClass());\n\n\t\tAspectJExpressionPointcut expressionPointcut = getPointcut(\n\t\t\t\tcandidateAdviceMethod, aspectInstanceFactory.getAspectMetadata().getAspectClass());\n\t\tif (expressionPointcut == null) {\n\t\t\treturn null;\n\t\t}","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java#L174-L210","documentation":"Thrown by ReflectiveAspectJAdvisorFactory.getDeclareParentsAdvisor() when a field annotated @DeclareParents does not specify a concrete defaultImpl (it still equals the marker default DeclareParents.class). Introduction (inter-type declaration) via @DeclareParents requires either defaultImpl (class-based) or delegate-ref (object-based); here the programmatic field-scan path needs defaultImpl set to a real implementation class.","triggerScenarios":"An @Aspect class has a field annotated @DeclareParents(value=\"...\", defaultImpl=DeclareParents.class) (i.e. the default untouched), and the aspect is processed by ReflectiveAspectJAdvisorFactory.getAdvisors(), which scans declared fields for @DeclareParents.","commonSituations":"Forgetting to set defaultImpl on a field-level @DeclareParents. Confusing the annotation-style (field) usage, which requires defaultImpl, with the XML <aop:declare-parents> usage that allows default-impl OR delegate-ref.","solutions":["Set defaultImpl to a concrete class implementing the introduced interface: @DeclareParents(value=\"com.acme..*+\", defaultImpl=DefaultFoo.class).","If you need a delegate instance rather than a default class, use XML <aop:declare-parents delegate-ref=\"...\"> instead of the field annotation."],"exampleFix":"// before\n@DeclareParents(value = \"com.acme.service.*+\", defaultImpl = DeclareParents.class)\nprivate UsageTracker usageTracker;\n// after\n@DeclareParents(value = \"com.acme.service.*+\", defaultImpl = DefaultUsageTracker.class)\nprivate UsageTracker usageTracker;","handlingStrategy":"validation","validationCode":"import org.aspectj.lang.annotation.DeclareParents;\nimport java.lang.reflect.Field;\n\nvoid validateDeclareParentsFields(Class<?> aspectClass) {\n  for (Field f : aspectClass.getDeclaredFields()) {\n    DeclareParents dp = f.getAnnotation(DeclareParents.class);\n    if (dp != null && dp.defaultImpl() == DeclareParents.class)\n      throw new IllegalStateException(\"Field \" + f + \" needs a concrete defaultImpl on @DeclareParents\");\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always specify defaultImpl on field-level @DeclareParents.","For delegate-instance introductions, use XML <aop:declare-parents delegate-ref=\"...\"> instead."],"tags":["spring-aop","aspectj","declare-parents","introduction","annotation"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}