gnodet-bot commented on code in PR #26824:
URL: https://github.com/apache/camel/pull/26824#discussion_r4091189100
##########
core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/BinaryExpression.java:
##########
@@ -58,10 +59,36 @@ public String toString() {
}
public boolean acceptLeftNode(SimpleNode lef) {
+ if (lef instanceof UnaryExpression unary && unary.getOperator() ==
UnaryOperatorType.NOT) {
+ // ! negates a function, not a comparison: !${body} == 'x' would
read as neither of the two things it
+ // could mean, so it is refused and the negated operator is
offered instead (CAMEL-24984)
+ throw new SimpleParserException(
+ "! cannot be compared: it negates a function, so negate
the operator instead, e.g. "
+ + operator.toString().replace("=",
"!=") + " or write "
Review Comment:
**Bug persists — `.replace("=", "!=")` still produces `"!=!="` for `==`.**
`negatedOperator()` was added to fix the second half of the message (after
`"or write"`), but the first half on this line still uses the broken replace.
For operator `==`, `operator.toString()` is `"=="`, `.replace("=", "!=")`
replaces every `=` independently, yielding `"!=!="`. The full error for
`!${body} == 'x'` would be:
> *"! cannot be compared: it negates a function, so negate the operator
instead, e.g. **!=!=** or write ${...} != value"*
The `negatedOperator()` call on the line below already produces the correct
`"!="` — the `.replace()` concatenation is now both wrong and redundant. Drop
line 67 entirely and call `negatedOperator()` once:
```suggestion
"! cannot be compared: it negates a function, so negate
the operator instead — write "
+ "${" + "..." + "} " +
negatedOperator() + " value",
```
--
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]