Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No error for misspelled dynamic finder #1554

Open
xpusostomos opened this issue Nov 21, 2021 · 0 comments
Open

No error for misspelled dynamic finder #1554

xpusostomos opened this issue Nov 21, 2021 · 0 comments

Comments

@xpusostomos
Copy link

I had a dynamic finder like this...

Set 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant