xpusostomos opened a new issue, #14417:
URL: https://github.com/apache/grails-core/issues/14417
I had a dynamic finder like this...
Set<AccountEntry> aes =
AccountEntry.findAllByDateGreaterThanEqualAndDateLessThanEqual(c.fromDate,
c.toDate)
And I couldn't figure out why it was generating a > and < SQL rather than >=
and <= SQL.
So it turned out to be my bad that it should be "Equals" rather than
"Equal". However, it's not good that this doesn't generate any error.
So it turns out that in DynamicFinder.java line 643, it tries to use regular
expressions to figure out which expression to use. This expression is generated
from DynamicFinder.java line 712...
\p{Upper}[\p{Lower}\d]+(Equal|NotEqual|NotInList|InList|InRange|Between|Like|Ilike|Rlike|GreaterThanEquals|LessThanEquals|GreaterThan|LessThan|IsNull|IsNotNull|IsEmpty|IsNotEmpty)
from...
private static void resetMethodExpressionPattern() {
String expressionPattern =
DefaultGroovyMethods.join((Iterable)methodExpressions.keySet(), "|");
methodExpressinPattern =
Pattern.compile("\\p{Upper}[\\p{Lower}\\d]+(" + expressionPattern + ")");
}
The trouble is, this expression isn't anchored at the end... so it matches
GreaterThan and generates no error about the "Equal" which it doesn't
understand.
It seems to me that if the expression generated from
resetMethodExpressionPattern was changed to end with "$"... the regex
end-anchor, it would generate an error about unrecognized "GreaterThanEqual"
and lead to more robust code from not having subtle errors that only manifest
in certain edge cases.
--
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]