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

org.mvel2.CompileException on Drools Template file with parameters in constraints #6154

Open
Cocoa-Puffs opened this issue Nov 18, 2024 · 0 comments

Comments

@Cocoa-Puffs
Copy link

Java Version: 21
Spring Boot Version: 3.3.4
KIE Version: 9.44.0.Final

Short summary:
In Drools Template files if there are parameters on a given line that end with a variable name a trailing space must be the last character of the line or during compiling an exception is thrown stating that unclosed @if{} blocks exist in the template file.

Detailed explanation:
Take for example the following drt snippet:

when
    $c: Customer($balances : balances != null)
    $b_thb: Balance(currency == "@{balanceType}") from $balances
then

Using either DataProviderCompiler or ObjectDataCompiler to compile the above I get the following error:

Caused by: org.mvel2.CompileException: [Error: unclosed @if{} block. expected @EnD{}]
[Near : {... nceType}");@EnD{} ....}]

The exception references the end of the action block. However when I replace the parameter with a concrete example:

when
    $c: Customer($balances : balances != null)
    $b_thb: Balance(currency == "MAGIC_COIN") from $balances
then

The exception does not come. After a bit of digging around with the debugger I have found that what happens is during compile time KIE wraps every line in if statements that use a parameter, for example the above snippet turns into:

when
    $c: Customer($balances : balances != null)
@if{balanceType != null}    $b_thb: Balance(currency == "@{balanceType}") from $balances@end{}
then

It then fails to read the @EnD{} statement as the closure of the if at the beginning of the line resulting in an exception. If I then modify the drt file to have a space at the end of this line the compilation is successful. Checking out the ExpressionNode using the debugger we can see the following:

when
    $c: Customer($balances : balances != null)
@if{balanceType != null}    $b_thb: Balance(currency == "@{balanceType}") from $balances @end{}
then
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