{"record":{"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/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java#L170-L206","documentation":"Thrown by AspectJExpressionPointcut.checkExpression() when getClassFilter() or getMethodMatcher() is called before the 'expression' property has been set. The pointcut cannot match anything without an AspectJ expression string.","triggerScenarios":"Creating an AspectJExpressionPointcut and immediately calling getClassFilter() or getMethodMatcher() without calling setExpression(...) first.","commonSituations":"Programmatic configuration that forgets to set the expression, or XML/annotation config that leaves the pointcut expression empty or null.","solutions":["Call setExpression(\"execution(...)\") before getClassFilter() / getMethodMatcher()","Inject an already-configured pointcut bean instead of constructing and configuring inline","Validate expression != null early in your configuration code"],"exampleFix":"// before\nAspectJExpressionPointcut pc = new AspectJExpressionPointcut();\npc.getClassFilter(); // throws\n\n// after\nAspectJExpressionPointcut pc = new AspectJExpressionPointcut();\npc.setExpression(\"execution(* com.example..*.*(..))\");\npc.getClassFilter();","handlingStrategy":"validation","validationCode":"// Validate expression is set before matching\nAspectJExpressionPointcut pc = new AspectJExpressionPointcut();\npc.setExpression(\"execution(* com.example..*.*(..))\");\nif (pc.getExpression() == null) {\n    throw new IllegalStateException(\"Expression must be set before matching\");\n}\npc.getClassFilter();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set the expression immediately after construction, before any match call","Prefer defining pointcuts via annotations (@Pointcut) or XML, which validate at load time","Inject pre-configured pointcut beans instead of building them inline"],"tags":["spring-aop","aspectj","pointcut","configuration"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}