Rule Template becomes unparseable due to "unclosed @if{} block. expected @end{}" error

Solution Verified - Updated -

Issue

  • There is an issue faced while using the spreadsheet based Decision Table along with RuleTemplate in a Drools 6 project. The issue specifically occurs when ExternalSpreadsheetCompiler API (to compile Decision Table and the Rule Template) of Drools is used during rule execution, where the following condition exists in the Rule Template
...
    String( this memberOf ParentFact.toStringList ( "@{childMemberFactList}" )
...

This is the exception thrown during rule execution.

Exception executing consequence for rule "TestRule" in org.drools.template.parser: java.lang.RuntimeException: [Error: unclosed @if{} block. expected @end{}]
[Near : {... != null}           "@{gruppe}",@end{} ....}]
                                          ^
[Line: 90, Column: 0]
    at org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
    at org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1057)
    at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:152)
    at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:94)
    at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:964)
    at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1234)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1239)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1212)
    at org.drools.template.parser.TemplateDataListener.finishSheet(TemplateDataListener.java:119)
    at org.drools.decisiontable.parser.xls.ExcelParser.finishSheet(ExcelParser.java:250)
    at org.drools.decisiontable.parser.xls.ExcelParser.processSheet(ExcelParser.java:192)
    at org.drools.decisiontable.parser.xls.ExcelParser.parseFile(ExcelParser.java:86)
    at org.drools.decisiontable.ExternalSpreadsheetCompiler.compile(ExternalSpreadsheetCompiler.java:140)
    at org.drools.decisiontable.ExternalSpreadsheetCompiler.compile(ExternalSpreadsheetCompiler.java:168)
    at org.drools.decisiontable.ExternalSpreadsheetCompiler.compile(ExternalSpreadsheetCompiler.java:99)
    at org.drools.decisiontable.ExternalSpreadsheetCompiler.compile(ExternalSpreadsheetCompiler.java:85)
    at com.sample.decisiontable.rule.test.DTRuleTestClass.testCompileRule(RegelsatzAusfuehrenTest.java:141)
Caused by: java.lang.RuntimeException: [Error: unclosed @if{} block. expected @end{}]
[Near : {... != null}           "@{gruppe}",@end{} ....}]
                                          ^
[Line: 90, Column: 0]
    at org.drools.template.parser.DefaultGenerator.generate(DefaultGenerator.java:80)
    at org.drools.template.parser.Rule_orhaben$u45$Regeln1016726609.defaultConsequence(Rule_orhaben$u45$Regeln1016726609.java:7)
    at org.drools.template.parser.Rule_orhaben$u45$Regeln1016726609DefaultConsequenceInvokerGenerated.evaluate(Unknown Source)
    at org.drools.template.parser.Rule_orhaben$u45$Regeln1016726609DefaultConsequenceInvoker.evaluate(Unknown Source)
    at org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1046)
    ... 16 more
Caused by: [Error: unclosed @if{} block. expected @end{}]
[Near : {... != null}           "@{gruppe}",@end{} ....}]
                                          ^
[Line: 90, Column: 0]
    at org.mvel2.templates.TemplateCompiler.compileFrom(TemplateCompiler.java:266)
    at org.mvel2.templates.TemplateCompiler.compile(TemplateCompiler.java:82)
    at org.mvel2.templates.TemplateCompiler.compileTemplate(TemplateCompiler.java:348)
    at org.drools.template.parser.DefaultGenerator.getTemplate(DefaultGenerator.java:102)
    at org.drools.template.parser.DefaultGenerator.generate(DefaultGenerator.java:59)
    ... 20 more
Exception in thread "main" java.lang.RuntimeException: Exception executing consequence for rule "TestRule" in org.drools.template.parser: java.lang.RuntimeException: [Error: unclosed @if{} block. expected @end{}]
[Near : {... != null}           "@{gruppe}",@end{} ....}]
                                          ^
[Line: 90, Column: 0]
    ...
  • Interestingly the issue does not occur if the aforementioned condition is modified like this way.
...
        childFact memberOf ParentFact.toStringList ( "@{childMemberFactList}" )
...

The purpose of ParentFact.toStringList ( "@{childMemberFactList}" is to have multiple string based Entries in the cell of the Spreadsheet based Decision Table like A,B and to transform this into an appropriate Collection - checking if the current Value is part of { "A","B" }. If user replaces the troubling condition with String( this memberOf ParentFact.toStringList ( "A,B" ) , i.e. hard coded String values, then there will be no error-message when parsing the files.

  • What is the root cause behind the issue and how it can be fixed?

Environment

  • Red Hat JBoss BRMS (BRMS)
    • 6.1.0

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content