{"id":"40d725efa0c958ac","repo":"spring-projects/spring-framework","slug":"must-set-property-expression-before-attempting-t","errorCode":null,"errorMessage":"Must set property 'expression' before attempting to match","messagePattern":"Must set property 'expression' before attempting to match","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java","lineNumber":188,"sourceCode":"\t@Override\n\tpublic ClassFilter getClassFilter() {\n\t\tcheckExpression();\n\t\treturn this;\n\t}\n\n\t@Override\n\tpublic MethodMatcher getMethodMatcher() {\n\t\tcheckExpression();\n\t\treturn this;\n\t}\n\n\n\t/**\n\t * Check whether this pointcut is ready to match.\n\t */\n\tprivate void checkExpression() {\n\t\tif (getExpression() == null) {\n\t\t\tthrow new IllegalStateException(\"Must set property 'expression' before attempting to match\");\n\t\t}\n\t}\n\n\t/**\n\t * Lazily build the underlying AspectJ pointcut expression.\n\t */\n\tprivate PointcutExpression obtainPointcutExpression() {\n\t\tPointcutExpression pointcutExpression = this.pointcutExpression;\n\t\tif (pointcutExpression == null) {\n\t\t\tClassLoader pointcutClassLoader = determinePointcutClassLoader();\n\t\t\tpointcutExpression = buildPointcutExpression(pointcutClassLoader);\n\t\t\tthis.pointcutClassLoader = pointcutClassLoader;\n\t\t\tthis.pointcutExpression = pointcutExpression;\n\t\t}\n\t\treturn pointcutExpression;\n\t}\n\n\t/**","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java#L170-L206","documentation":"Thrown by AspectJExpressionPointcut.checkExpression (called by getClassFilter/getMethodMatcher and matching operations) when the 'expression' property was never set. Without an expression the pointcut cannot be parsed or evaluated.","triggerScenarios":"Creating an AspectJExpressionPointcut via the no-arg constructor and calling getClassFilter(), getMethodMatcher(), or any match() method before calling setExpression().","commonSituations":"Programmatic pointcut creation where setExpression is skipped or called with null; misconfigured XML/annotation where the expression attribute is blank; bean wiring that instantiates the pointcut but never injects the expression.","solutions":["Call setExpression(\"execution(...))\") before any match or filter access.","If configuring via XML/annotations, verify the 'expression' attribute is present and non-empty.","Use the constructor/setter order: construct, setExpression, then use."],"exampleFix":"// before\nAspectJExpressionPointcut pc = new AspectJExpressionPointcut();\npc.getClassFilter(); // throws\n\n// after\nAspectJExpressionPointcut pc = new AspectJExpressionPointcut();\npc.setExpression(\"execution(* com.acme..*.*(..))\");\npc.getClassFilter();","handlingStrategy":"validation","validationCode":"if (pointcut.getExpression() == null || pointcut.getExpression().isBlank()) {\n    throw new IllegalStateException(\"expression must be set\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call setExpression immediately after constructing the pointcut.","Validate configuration in a @PostConstruct or test.","Use XML/annotation config which forces the expression attribute."],"tags":["spring-aop","aspectj","pointcut","configuration"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}