{"id":"cc4c34fbf1a335f0","repo":"spring-projects/spring-framework","slug":"unknown-advice-kind","errorCode":null,"errorMessage":"Unknown advice kind [{}].","messagePattern":"Unknown advice kind \\[(.+?)\\]\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java","lineNumber":412,"sourceCode":"\t\t}\n\n\t\tcav.addIndexedArgumentValue(ASPECT_INSTANCE_FACTORY_INDEX, aspectFactoryDef);\n\n\t\treturn adviceDefinition;\n\t}\n\n\t/**\n\t * Gets the advice implementation class corresponding to the supplied {@link Element}.\n\t */\n\tprivate Class<?> getAdviceClass(Element adviceElement, ParserContext parserContext) {\n\t\tString elementName = parserContext.getDelegate().getLocalName(adviceElement);\n\t\treturn switch (elementName) {\n\t\t\tcase BEFORE -> AspectJMethodBeforeAdvice.class;\n\t\t\tcase AFTER -> AspectJAfterAdvice.class;\n\t\t\tcase AFTER_RETURNING_ELEMENT -> AspectJAfterReturningAdvice.class;\n\t\t\tcase AFTER_THROWING_ELEMENT -> AspectJAfterThrowingAdvice.class;\n\t\t\tcase AROUND -> AspectJAroundAdvice.class;\n\t\t\tdefault -> throw new IllegalArgumentException(\"Unknown advice kind [\" + elementName + \"].\");\n\t\t};\n\t}\n\n\t/**\n\t * Parses the supplied {@code <pointcut>} and registers the resulting\n\t * Pointcut with the BeanDefinitionRegistry.\n\t */\n\tprivate AbstractBeanDefinition parsePointcut(Element pointcutElement, ParserContext parserContext) {\n\t\tString id = pointcutElement.getAttribute(ID);\n\t\tString expression = pointcutElement.getAttribute(EXPRESSION);\n\n\t\tAbstractBeanDefinition pointcutDefinition = null;\n\n\t\ttry {\n\t\t\tthis.parseState.push(new PointcutEntry(id));\n\t\t\tpointcutDefinition = createPointcutDefinition(expression);\n\t\t\tpointcutDefinition.setSource(parserContext.extractSource(pointcutElement));\n","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java#L394-L430","documentation":"Thrown by ConfigBeanDefinitionParser.getAdviceClass() in the default branch of the switch over the local element name when parsing an <aop:config><aspect> child element. Only the five advice element names are recognized (before, after, after-returning, after-throwing, around). Reaching the default branch means the parser was handed an element whose local name is none of these — which the XML schema should prevent, so this typically indicates a schema/custom-element processing issue.","triggerScenarios":"Parsing an <aop:config> document containing a child element under <aspect> whose local name is not one of before/after/after-returning/after-throwing/around, yet passed isAdviceNode filtering. Reachable if the XML schema validation is disabled or a custom namespace slips an unrecognized advice-like element in.","commonSituations":"Disabling XML schema validation and hand-editing <aop:config> with an invalid advice tag (e.g. <aop:after-completing>). A typo in an advice element name. A malformed namespace handler producing unexpected child elements.","solutions":["Ensure the <aop:config> XML is schema-validated and uses only the five valid advice element names.","Correct any typo in the advice element name (before, after, after-returning, after-throwing, around).","Remove custom/unrecognized elements from inside <aspect>."],"exampleFix":"<!-- before -->\n<aop:config>\n  <aop:aspect ref=\"audit\">\n    <aop:before-logging method=\"log\" pointcut=\"execution(* *(..))\"/>\n  </aop:aspect>\n</aop:config>\n<!-- after -->\n<aop:config>\n  <aop:aspect ref=\"audit\">\n    <aop:before method=\"log\" pointcut=\"execution(* *(..))\"/>\n  </aop:aspect>\n</aop:config>","handlingStrategy":"validation","validationCode":"import org.w3c.dom.Element;\nimport java.util.Set;\n\nvoid validateAdviceElements(Element aspectElement) {\n  Set<String> valid = Set.of(\"before\",\"after\",\"after-returning\",\"after-throwing\",\"around\");\n  var kids = aspectElement.getChildNodes();\n  for (int i = 0; i < kids.getLength(); i++) {\n    if (kids.item(i) instanceof Element e && \"aop\".equals(e.getNamespaceURI()) && !valid.contains(e.getLocalName()))\n      throw new IllegalArgumentException(\"Unknown <aop:*> advice element: \" + e.getLocalName());\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep XML schema validation enabled so invalid advice elements are rejected by the schema first.","Use only the five canonical advice element names under <aop:aspect>.","Prefer @AspectJ annotation style over XML <aop:config> to avoid hand-editing errors."],"tags":["spring-aop","xml-config","advice","schema","configuration"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}