Quantcast

java.lang.ClassCastException comparing BigDecimals (compareTo)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

java.lang.ClassCastException comparing BigDecimals (compareTo)

José Arrarte
Hello,

First of all, I'd like to thank all the people involved in making this tool such a great one (this includes whoever writes the reference manual as well).

I've been having some problems when comparing BigDecimals (using the compareTo method). I didn't find this issue in any previous post or in Drools' JIRA. However, I've been using Drools for a short time, so I hope you people can help me.

The problem:

Firing this (simple) rule:

rule "Test Rule"
  when
      $dec : java.math.BigDecimal() from java.math.BigDecimal.TEN;
      eval( $dec.compareTo(java.math.BigDecimal.ONE) > 0 )
  then
      System.out.println("OK!");
end

Fires this exception:

org.drools.RuntimeDroolsException: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigDecimal
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:76)
at org.drools.reteoo.EvalConditionNode.assertTuple(EvalConditionNode.java:145)
at org.drools.reteoo.SingleTupleSinkAdapter.propagateAssertTuple(SingleTupleSinkAdapter.java:20)
at org.drools.reteoo.FromNode.assertTuple(FromNode.java:90)
at org.drools.reteoo.SingleTupleSinkAdapter.createAndPropagateAssertTuple(SingleTupleSinkAdapter.java:55)
at org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:116)
at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:22)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:153)
at org.drools.reteoo.Rete.assertObject(Rete.java:175)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
at org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute(ReteooWorkingMemory.java:179)
at org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:1315)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:462)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:433)
at com.sample.DroolsTest.main(DroolsTest.java:33)
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigDecimal
at com.sample.Rule_Test_Rule_0Eval0Invoker.evaluate(Rule_Test_Rule_0Eval0Invoker.java:12)
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:72)
... 14 more

I've reported the issue in JIRA (http://jira.jboss.com/jira/browse/JBRULES-1433)

Best regards,
José

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.lang.ClassCastException comparing BigDecimals (compareTo)

Michael Neale
hmmm... have you tried setting "dialect 'mvel' " for the rule/package? 

I am not sure if you can do that even in java 5 (but in MVEL we can make it happen if it doesn't already).

On Jan 25, 2008 11:19 PM, José Arrarte <[hidden email]> wrote:
Hello,

First of all, I'd like to thank all the people involved in making this tool such a great one (this includes whoever writes the reference manual as well).

I've been having some problems when comparing BigDecimals (using the compareTo method). I didn't find this issue in any previous post or in Drools' JIRA. However, I've been using Drools for a short time, so I hope you people can help me.

The problem:

Firing this (simple) rule:

rule "Test Rule"
  when
      $dec : java.math.BigDecimal() from java.math.BigDecimal.TEN;
      eval( $dec.compareTo(java.math.BigDecimal.ONE) > 0 )
  then
      System.out.println("OK!");
end

Fires this exception:

org.drools.RuntimeDroolsException: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigDecimal
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:76)
at org.drools.reteoo.EvalConditionNode.assertTuple(EvalConditionNode.java:145)
at org.drools.reteoo.SingleTupleSinkAdapter.propagateAssertTuple(SingleTupleSinkAdapter.java:20)
at org.drools.reteoo.FromNode.assertTuple(FromNode.java:90)
at org.drools.reteoo.SingleTupleSinkAdapter.createAndPropagateAssertTuple(SingleTupleSinkAdapter.java:55)
at org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:116)
at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:22)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:153)
at org.drools.reteoo.Rete.assertObject(Rete.java:175)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
at org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute(ReteooWorkingMemory.java:179)
at org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:1315)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:462)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:433)
at com.sample.DroolsTest.main(DroolsTest.java:33)
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigDecimal
at com.sample.Rule_Test_Rule_0Eval0Invoker.evaluate(Rule_Test_Rule_0Eval0Invoker.java:12)
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:72)
... 14 more

I've reported the issue in JIRA (http://jira.jboss.com/jira/browse/JBRULES-1433)

Best regards,
José

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users




--
Michael D Neale
home: www.michaelneale.net
blog: michaelneale.blogspot.com

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.lang.ClassCastException comparing BigDecimals (compareTo)

Edson Tirelli-3
In reply to this post by José Arrarte
 
      Looks like a bug to me. May I ask you plz to open a JIRA?

      []s
      Edson

2008/1/25, José Arrarte <[hidden email]>:
Hello,

First of all, I'd like to thank all the people involved in making this tool such a great one (this includes whoever writes the reference manual as well).

I've been having some problems when comparing BigDecimals (using the compareTo method). I didn't find this issue in any previous post or in Drools' JIRA. However, I've been using Drools for a short time, so I hope you people can help me.

The problem:

Firing this (simple) rule:

rule "Test Rule"
  when
      $dec : java.math.BigDecimal() from java.math.BigDecimal.TEN;
      eval( $dec.compareTo(java.math.BigDecimal.ONE) > 0 )
  then
      System.out.println("OK!");
end

Fires this exception:

org.drools.RuntimeDroolsException: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigDecimal
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:76)
at org.drools.reteoo.EvalConditionNode.assertTuple(EvalConditionNode.java:145)
at org.drools.reteoo.SingleTupleSinkAdapter.propagateAssertTuple(SingleTupleSinkAdapter.java:20)
at org.drools.reteoo.FromNode.assertTuple(FromNode.java:90)
at org.drools.reteoo.SingleTupleSinkAdapter.createAndPropagateAssertTuple(SingleTupleSinkAdapter.java:55)
at org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:116)
at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:22)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:153)
at org.drools.reteoo.Rete.assertObject(Rete.java:175)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
at org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute(ReteooWorkingMemory.java:179)
at org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:1315)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:462)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:433)
at com.sample.DroolsTest.main(DroolsTest.java:33)
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigDecimal
at com.sample.Rule_Test_Rule_0Eval0Invoker.evaluate(Rule_Test_Rule_0Eval0Invoker.java:12)
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:72)
... 14 more

I've reported the issue in JIRA (<a href="http://jira.jboss.com/jira/browse/JBRULES-1433" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://jira.jboss.com/jira/browse/JBRULES-1433)

Best regards,
José

_______________________________________________
rules-users mailing list
[hidden email]
<a onclick="return top.js.OpenExtLink(window,event,this)" href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users




--
  Edson Tirelli
  JBoss Drools Core Development
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: java.lang.ClassCastException comparing BigDecimals (compareTo)

José Arrarte
Hello again. I was out of office, sorry for not answering sooner...
 
I've opened a JIRA issue, #1433, with a test case and a full stack trace desciption:
 

Best regards,
José Arrarte
On Jan 30, 2008 9:55 AM, Edson Tirelli <[hidden email]> wrote:
 
      Looks like a bug to me. May I ask you plz to open a JIRA?

      []s
      Edson

2008/1/25, José Arrarte <[hidden email]>:
Hello,

First of all, I'd like to thank all the people involved in making this tool such a great one (this includes whoever writes the reference manual as well).

I've been having some problems when comparing BigDecimals (using the compareTo method). I didn't find this issue in any previous post or in Drools' JIRA. However, I've been using Drools for a short time, so I hope you people can help me.

The problem:

Firing this (simple) rule:

rule "Test Rule"
  when
      $dec : java.math.BigDecimal() from java.math.BigDecimal.TEN;
      eval( $dec.compareTo(java.math.BigDecimal.ONE) > 0 )
  then
      System.out.println("OK!");
end

Fires this exception:

org.drools.RuntimeDroolsException: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigDecimal
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:76)
at org.drools.reteoo.EvalConditionNode.assertTuple(EvalConditionNode.java:145)
at org.drools.reteoo.SingleTupleSinkAdapter.propagateAssertTuple(SingleTupleSinkAdapter.java:20)
at org.drools.reteoo.FromNode.assertTuple(FromNode.java:90)
at org.drools.reteoo.SingleTupleSinkAdapter.createAndPropagateAssertTuple(SingleTupleSinkAdapter.java:55)
at org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:116)
at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:22)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:153)
at org.drools.reteoo.Rete.assertObject(Rete.java:175)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
at org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute(ReteooWorkingMemory.java:179)
at org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:1315)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:462)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:433)
at com.sample.DroolsTest.main(DroolsTest.java:33)
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigDecimal
at com.sample.Rule_Test_Rule_0Eval0Invoker.evaluate(Rule_Test_Rule_0Eval0Invoker.java:12)
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:72)
... 14 more

I've reported the issue in JIRA (http://jira.jboss.com/jira/browse/JBRULES-1433)

Best regards,
José

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users




--
  Edson Tirelli
  JBoss Drools Core Development
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Loading...