Drools Rule Template error [Error: unclosed @if{} block. expected @end{}] when placeholder is used

184 Views Asked by At

drools rule template cannot be compiled if placeholder is used in subclass collection list.

I have this simple class structure

public class Parent {
   private List<Child> children;
}
public class Child {
   private String gender;
}

When placeholder @{gender} is used, ExternalSpreadsheetCompiler throw error [Error: unclosed @if{} block. expected @end{}]

Parent($children: children)
Child(gender == "@{gender}") from $children

No issue when "MALE" is hardcoded in the template

Parent($children: children)
Child(gender == "MALE") from $children

Any idea? Thanks for your help.

Full error stack trace :

[Line: 42, Column: 0]
    at org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
    at org.drools.core.common.DefaultAgenda.handleException(DefaultAgenda.java:1291)
    at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:442)
    at org.drools.core.phreak.RuleExecutor.fireActivation(RuleExecutor.java:380)
    at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:136)
    at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:89)
    at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:33)
    at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
    at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1101)
    at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1048)
    at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1040)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1341)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1332)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1316)
    at org.drools.template.parser.TemplateDataListener.finishSheet(TemplateDataListener.java:158)
    at org.drools.decisiontable.parser.xls.ExcelParser.finishSheet(ExcelParser.java:277)
    at org.drools.decisiontable.parser.xls.ExcelParser.processSheet(ExcelParser.java:212)
    at org.drools.decisiontable.parser.xls.ExcelParser.parseWorkbook(ExcelParser.java:105)
    at org.drools.decisiontable.parser.xls.ExcelParser.parseFile(ExcelParser.java:84)
    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.dhl.gssdemo.config.SpringDroolsConfig.addTemplateContent(SpringDroolsConfig.java:112)
    at com.dhl.gssdemo.config.SpringDroolsConfig.classpathDrlKieBase(SpringDroolsConfig.java:102)
    at com.dhl.gssdemo.config.SpringDroolsConfig$$EnhancerBySpringCGLIB$$583d8208.CGLIB$classpathDrlKieBase$0(<generated>)
    at com.dhl.gssdemo.config.SpringDroolsConfig$$EnhancerBySpringCGLIB$$583d8208$$FastClassBySpringCGLIB$$25a5fef6.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
    at com.dhl.gssdemo.config.SpringDroolsConfig$$EnhancerBySpringCGLIB$$583d8208.classpathDrlKieBase(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 52 common frames omitted
Caused by: java.lang.RuntimeException: [Error: unclosed @if{} block. expected @end{}]
1

There are 1 best solutions below

1
On

I had the same issue I think its related to resolving MVEL expression but I resolved it by using the following workaround (use $$ instead of $)

E.g in your case

Parent($children: children) Child(gender == "@{gender}") from $$children