gnodet-bot commented on code in PR #26824:
URL: https://github.com/apache/camel/pull/26824#discussion_r4090893279


##########
core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/UnaryExpression.java:
##########
@@ -79,11 +86,31 @@ public Expression createExpression(CamelContext 
camelContext, String expression)
             return createIncDecExpression(camelContext, leftExp, 1);
         } else if (operator == UnaryOperatorType.DEC) {
             return createIncDecExpression(camelContext, leftExp, -1);
+        } else if (operator == UnaryOperatorType.NOT) {
+            return createNotExpression(camelContext, leftExp);
         }
 
         throw new SimpleParserException("Unknown unary operator " + operator, 
token.getIndex());
     }
 
+    private Expression createNotExpression(CamelContext camelContext, final 
Expression exp) {
+        return new Expression() {
+            @Override
+            public <T> T evaluate(Exchange exchange, Class<T> type) {

Review Comment:
   ⚠️ **Missing `init()` override — `exp` is never initialized before 
`evaluate()` is called.**
   
   `SimpleFunctionExpression.createNegatedExpression` (the `${!...}` path) 
correctly adds:
   ```java
   @Override
   public void init(CamelContext context) {
       exp.init(context);
   }
   ```
   This method, which handles the outer `!${...}` path, must do the same. 
Without it, callers that follow the standard `p.init(context)` → 
`p.evaluate(...)` lifecycle will invoke a no-op `init()` on the returned 
expression, skipping `exp.init(context)`. Any function that sets up internal 
state in `init()` (e.g. OGNL method handles, compiled patterns) will NPE or 
return incorrect results on first `evaluate()`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to