Details
-
Bug
-
Resolution: Done
-
Minor
-
5.1.1.FINAL
Description
I posted this to the "rules-users" list, and did not get a response. That leads me to believe it is a bug, so I'm submitting it here. Below is the text of my email.
Using org.drools.verifier found in "drools-verifier-5.1.1.jar" I get an org.drools.RuntimeDroolsException if a pattern in a rule LHS contains a comparison to a literal value using the equals operator.
Please consider the following rule I created solely for the purposes of isolating this issue.
package com.simple.test.rule
import com.p1s.mps.rulevalidator.TestFact;
rule "TestRule"
when
$fact : TestFact(value == 1)
then
System.out.println($fact.getValue());
end
The following class definition for the TestFact.
package com.p1s.mps.rulevalidator;
public class TestFact
{
private int value;
public TestFact(int value)
{ this.value = value; }public int getValue() { return value; }
public void setValue(int value) { this.value = value; }
@Override
public int hashCode()
@Override
public boolean equals(Object obj)
}
The following unit test which attempts to use Verifier.
@Test
public final void testVerifierOnLiteral()
Running the test with JUnit produces the following exception.
java.lang.RuntimeException: org.drools.RuntimeDroolsException: Exception executing ReturnValue constraint org.drools.rule.ReturnValueRestriction@589f81 : [Error: cannot convert <1> to a numeric type: class java.lang.Integer [0]]
[Near :
^
[Line: 1, Column: 0]
at org.drools.verifier.builder.VerifierImpl.analyse(VerifierImpl.java:148)
at org.drools.verifier.builder.VerifierImpl.fireAnalysis(VerifierImpl.java:117)
at com.p1s.mps.rulevalidator.NumericConversionTest.testVerifierOnLiteral(NumericConversionTest.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.drools.RuntimeDroolsException: Exception executing ReturnValue constraint org.drools.rule.ReturnValueRestriction@589f81 : [Error: cannot convert <1> to a numeric type: class java.lang.Integer [0]]
[Near : {... Unknown ....}
]
^
[Line: 1, Column: 0]
at org.drools.rule.ReturnValueConstraint.isAllowedCachedRight(ReturnValueConstraint.java:168)
at org.drools.common.TripleBetaConstraints.isAllowedCachedRight(TripleBetaConstraints.java:211)
at org.drools.reteoo.NotNode.assertObject(NotNode.java:140)
at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:59)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:145)
at org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:450)
at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:378)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:190)
at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:145)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1174)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1123)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:917)
at org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:251)
at org.drools.verifier.builder.VerifierImpl.analyse(VerifierImpl.java:136)
... 26 more
Caused by: org.drools.RuntimeDroolsException: [Error: cannot convert <1> to a numeric type: class java.lang.Integer [0]]
[Near :
^
[Line: 1, Column: 0]
at org.drools.rule.ReturnValueRestriction.isAllowed(ReturnValueRestriction.java:236)
at org.drools.rule.ReturnValueConstraint.isAllowedCachedRight(ReturnValueConstraint.java:162)
... 39 more
Caused by: [Error: cannot convert <1> to a numeric type: class java.lang.Integer [0]]
[Near : {... Unknown ....}
]
^
[Line: 1, Column: 0]
at org.mvel2.math.MathProcessor.getInternalNumberFromType(MathProcessor.java:577)
at org.mvel2.math.MathProcessor._doOperations(MathProcessor.java:155)
at org.mvel2.math.MathProcessor.doOperations(MathProcessor.java:79)
at org.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:102)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:104)
at org.mvel2.MVEL.executeExpression(MVEL.java:978)
at org.drools.base.mvel.MVELReturnValueExpression.evaluate(MVELReturnValueExpression.java:92)
at org.drools.rule.ReturnValueRestriction.isAllowed(ReturnValueRestriction.java:226)
... 40 more
However, if I use the following version of the same rule where I have added parentheses it works.
package com.simple.test.rule
import com.p1s.mps.rulevalidator.TestFact;
rule "TestRule"
when
$fact : TestFact(value == (1))
then
System.out.println($fact.getValue());
end
Note that both versions of the DRL file compile, run, and produce the correct results.