Bug 1242010 - Rule Templates do not completely ignore single commented lines which are invalid
Summary: Rule Templates do not completely ignore single commented lines which are invalid
Keywords:
Status: CLOSED EOL
Alias: None
Product: JBoss BRMS Platform 6
Classification: Retired
Component: BRE
Version: 6.1.0
Hardware: All
OS: All
high
high
Target Milestone: ER1
: 6.2.0
Assignee: Mario Fusco
QA Contact: Tomas David
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-07-10 15:40 UTC by Musharraf Hussain
Modified: 2020-03-27 20:09 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-03-27 20:09:58 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
DroolsTemplateCommentTest.zip (22.72 KB, application/zip)
2015-07-10 15:40 UTC, Musharraf Hussain
no flags Details

Description Musharraf Hussain 2015-07-10 15:40:07 UTC
Created attachment 1050727 [details]
DroolsTemplateCommentTest.zip

Description of problem:
- This issue is related to the capabilities of Drools compiler to ignore Single line comment in Rule Template files. Imagine there is a rule template which has the following template headers defined inside it.
~~~
template header
age
type
log
~~~

- However, by mistake you write a template rule which uses a header information which is not listed above. Now, you want to comment that line so as to ensure that your Drools compiler ignores it.
~~~
template "cheesefans"

rule "Cheese fans_@{row.rowNumber}"
dialect "java" 
    when
        $person: Person(age == "@{age}")
        $cheese: Cheese(type == "@{type}")
        
        // $cheeseInvalid: Cheese(type == "@{typeFault}") 
	...	
~~~

- Now, if we try to execute this template inside "ExternalSpreadsheetCompiler.compile(..)" method it complains with the following exception.
~~~
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" Exception executing consequence for rule "cheesefans" in org.drools.template.parser: java.lang.RuntimeException: [Error: unable to resolve method: java.util.HashMap.typeFault() [arglength=0]]
[Near : {... rule "Cheese fans_@{row.rowNum ....}]
             ^
[Line: 1, Column: 1]
	at org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
	at org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1125)
	at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:160)
	at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:108)
	at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1016)
	at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1302)
	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1289)
	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1262)
	at org.drools.template.parser.TemplateDataListener.finishSheet(TemplateDataListener.java:119)
	at org.drools.decisiontable.parser.xls.ExcelParser.finishSheet(ExcelParser.java:244)
	at org.drools.decisiontable.parser.xls.ExcelParser.processSheet(ExcelParser.java:186)
	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 org.drools.examples.templates.SimpleRuleTemplateExample.buildKBase(SimpleRuleTemplateExample.java:85)
	at org.drools.examples.templates.SimpleRuleTemplateExample.executeExample(SimpleRuleTemplateExample.java:50)
	at org.drools.examples.templates.SimpleRuleTemplateExample.main(SimpleRuleTemplateExample.java:44)
Caused by: java.lang.RuntimeException: [Error: unable to resolve method: java.util.HashMap.typeFault() [arglength=0]]
[Near : {... rule "Cheese fans_@{row.rowNum ....}]
             ^
[Line: 1, Column: 1]
	at org.drools.template.parser.DefaultGenerator.generate(DefaultGenerator.java:80)
	at org.drools.template.parser.Rule_cheesefans1206731317.defaultConsequence(Rule_cheesefans1206731317.java:7)
	at org.drools.template.parser.Rule_cheesefans1206731317DefaultConsequenceInvokerGenerated.evaluate(Unknown Source)
	at org.drools.template.parser.Rule_cheesefans1206731317DefaultConsequenceInvoker.evaluate(Unknown Source)
	at org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1114)
	... 17 more
Caused by: [Error: unable to resolve method: java.util.HashMap.typeFault() [arglength=0]]
[Near : {... rule "Cheese fans_@{row.rowNum ....}]
             ^
[Line: 1, Column: 1]
	at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1094)
	at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1003)
	at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanProperty(ReflectiveAccessorOptimizer.java:693)
	at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:360)
	at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:163)
	at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
	at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
	at org.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:117)
	at org.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:42)
	at org.mvel2.MVEL.executeExpression(MVEL.java:930)
	at org.mvel2.MVEL.executeExpression(MVEL.java:991)
	at org.mvel2.templates.res.CompiledIfNode.eval(CompiledIfNode.java:43)
	at org.mvel2.templates.res.TextNode.eval(TextNode.java:42)
	at org.mvel2.templates.res.TerminalNode.eval(TerminalNode.java:35)
	at org.mvel2.templates.res.TextNode.eval(TextNode.java:42)
	at org.mvel2.templates.res.CompiledExpressionNode.eval(CompiledExpressionNode.java:46)
	at org.mvel2.templates.res.TextNode.eval(TextNode.java:42)
	at org.mvel2.templates.res.CompiledIfNode.eval(CompiledIfNode.java:44)
	at org.mvel2.templates.res.TextNode.eval(TextNode.java:42)
	at org.mvel2.templates.res.TerminalNode.eval(TerminalNode.java:35)
	at org.mvel2.templates.res.TextNode.eval(TextNode.java:42)
	at org.mvel2.templates.res.CompiledExpressionNode.eval(CompiledExpressionNode.java:46)
	at org.mvel2.templates.res.TextNode.eval(TextNode.java:42)
	at org.mvel2.templates.res.CompiledIfNode.eval(CompiledIfNode.java:44)
	at org.mvel2.templates.res.TextNode.eval(TextNode.java:42)
	at org.mvel2.templates.res.CompiledExpressionNode.eval(CompiledExpressionNode.java:46)
	at org.mvel2.templates.res.TextNode.eval(TextNode.java:42)
	at org.mvel2.templates.res.TextNode.eval(TextNode.java:42)
	at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:285)
	at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:247)
	at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:255)
	at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:207)
	at org.drools.template.parser.DefaultGenerator.generate(DefaultGenerator.java:73)
	... 21 more

~~~

- The question is , even if I have commented that mistaken line with single line comment ("//") , why does Drools compiler throws this issue? The reason why it is an issue with the compilation as you can workaround this issue if you replace the commented line's template header with a valid one.
~~~
        // $cheeseInvalid: Cheese(type == "@{type}") 
~~~

Please investigate this issue.

Version-Release number of selected component (if applicable):
- BRMS 6.1.0
- Drools 6.2.0

How reproducible:
- Always

Steps to Reproduce:
1. Import the attached project "DroolsTemplateCommentTest.zip" in JBDS/Eclipse.
2. Run the "org.drools.examples.templates.SimpleRuleTemplateExample" class as a "Java Application" from the IDE.
3. You should see the exception as quoted above.

Actual results:
- It throws the exception quoted above.

Expected results:
- It should have run fine.

Additional info:
- Nothing

Comment 2 Mario Fusco 2015-07-13 09:28:22 UTC
Fixed by https://github.com/droolsjbpm/drools/commit/546ca6f38

Comment 3 Tomas David 2015-10-23 11:36:01 UTC
Verified on BRMS 6.2.0.ER4.


Note You need to log in before you can comment on or make changes to this bug.