{"record":{"id":"93f145cf9df0d4b6","repo":"spring-projects/spring-framework","slug":"invalid-expression-at-location-location-ex","errorCode":null,"errorMessage":"Invalid expression at location [{location}]: {ex}","messagePattern":"Invalid expression at location \\[(.+?)\\]: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/support/AbstractExpressionPointcut.java","lineNumber":66,"sourceCode":"\t/**\n\t * Return location information about the pointcut expression\n\t * if available. This is useful in debugging.\n\t * @return location information as a human-readable String,\n\t * or {@code null} if none is available\n\t */\n\tpublic @Nullable String getLocation() {\n\t\treturn this.location;\n\t}\n\n\tpublic void setExpression(@Nullable String expression) {\n\t\tthis.expression = expression;\n\t\ttry {\n\t\t\tonSetExpression(expression);\n\t\t}\n\t\tcatch (IllegalArgumentException ex) {\n\t\t\t// Fill in location information if possible.\n\t\t\tif (this.location != null) {\n\t\t\t\tthrow new IllegalArgumentException(\"Invalid expression at location [\" + this.location + \"]: \" + ex);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow ex;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Called when a new pointcut expression is set.\n\t * The expression should be parsed at this point if possible.\n\t * <p>This implementation is empty.\n\t * @param expression the expression to set\n\t * @throws IllegalArgumentException if the expression is invalid\n\t * @see #setExpression\n\t */\n\tprotected void onSetExpression(@Nullable String expression) throws IllegalArgumentException {\n\t}\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/support/AbstractExpressionPointcut.java#L48-L84","documentation":"Thrown by AbstractExpressionPointcut.setExpression (line 58-71) when the subclass's onSetExpression(expression) raises an IllegalArgumentException (e.g. a malformed AspectJ pointcut expression) AND a location string was previously set via setLocation(...). The original parse error is re-thrown wrapped with the location prefix to make debugging easier; if no location was set, the raw exception propagates.","triggerScenarios":"Configuring an AspectJExpressionPointcut (or other AbstractExpressionPointcut subclass) with a syntactically invalid expression - e.g. 'execution(()' , 'executon(* ..*(..))', undefined type references - and having called setLocation(...) to tag the source. onSetExpression parses the expression immediately and throws.","commonSituations":"Typos in AspectJ pointcut expressions (execution/within/args). Referencing a type or method signature that does not exist or is not on the classpath. Copying an expression from a newer AspectJ version into an older Spring. XML-configured pointcuts where the location is the XML resource id.","solutions":["Correct the pointcut expression syntax - validate it against AspectJ grammar (e.g. 'execution(* com.example.Service.*(..))').","Ensure all referenced types are on the classpath and fully qualified where needed.","If the message includes a location, inspect that source (XML id / programmatic label) to find which pointcut is misconfigured.","Use the AspectJ parser/IDE plugin or Spring's PointcutExpression unit tests to confirm validity before deployment."],"exampleFix":"// before\nAspectJExpressionPointcut pc = new AspectJExpressionPointcut();\npc.setLocation(\"servicePointcut\");\npc.setExpression(\"executon(* com.example.Service.*(..))\"); // typo\n\n// after\npc.setExpression(\"execution(* com.example.Service.*(..))\");","handlingStrategy":"validation","validationCode":"AspectJExpressionPointcut pc = new AspectJExpressionPointcut();\ntry {\n    pc.setExpression(expr); // throws on invalid\n} catch (IllegalArgumentException e) {\n    // log and reject the configuration\n}","typeGuard":null,"tryCatchPattern":"try {\n    pc.setExpression(candidateExpr);\n} catch (IllegalArgumentException e) {\n    logger.warn(\"Invalid pointcut expression: \" + candidateExpr, e);\n    // fall back to a safe default expression\n}","preventionTips":["Validate AspectJ expressions in unit tests before deploying config.","Set a location string via setLocation for clearer error messages.","Fully qualify types and double-check execution/within/args syntax."],"tags":["spring-aop","pointcut","aspectj","expression","configuration"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}