{"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/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/support/AbstractExpressionPointcut.java#L48-L84","documentation":"AbstractExpressionPointcut.setExpression catches an IllegalArgumentException thrown by onSetExpression (typically the AspectJ pointcut parser rejecting malformed syntax) and, when a debug location was set via setLocation, rethrows it with the location prepended for easier diagnosis. The original parse exception is the cause.","triggerScenarios":"Calling pointcut.setExpression(\"execution(* com.acme.*.bar(\") (unbalanced parenthesis) on an expression pointcut that had setLocation(\"fooPointcut\") called beforehand.","commonSituations":"Typos in AspectJ execution()/within() expressions; copy-pasting a pointcut from documentation with smart quotes; mismatched wildcards; upgrading Spring/AspectJ versions that tighten parsing.","solutions":["Fix the pointcut expression syntax (balance parentheses, valid designators, correct wildcard patterns).","Call setLocation(\"myPointcut\") before setExpression so the wrapped message names the offending definition.","Validate expressions in a unit test using AspectJExpressionPointcut before deploying."],"exampleFix":"// before\nAspectJExpressionPointcut pc = new AspectJExpressionPointcut();\npc.setLocation(\"servicePointcut\");\npc.setExpression(\"execution(* com.acme.*.bar(\"); // unbalanced -> error 112\n\n// after\npc.setExpression(\"execution(* com.acme..*.*(..))\");","handlingStrategy":"try-catch","validationCode":"AspectJExpressionPointcut pc = new AspectJExpressionPointcut();\npc.setLocation(\"test\");\ntry {\n    pc.setExpression(expr);\n} catch (IllegalArgumentException ex) {\n    // expr is invalid; reject configuration at load time\n}","typeGuard":null,"tryCatchPattern":"try {\n    pointcut.setExpression(expr);\n} catch (IllegalArgumentException ex) {\n    log.error(\"Invalid pointcut expression: {}\", expr, ex);\n    throw ex;\n}","preventionTips":["Always call setLocation before setExpression to improve error messages.","Unit-test pointcut expressions with a quick AspectJExpressionPointcut smoke test.","Lint expression strings at config-load time."],"tags":["spring-aop","pointcut","expression","aspectj","configuration"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}