<br>   Steve and all users of Drools 4,<br><br>   Although earlier versions of Drools used mvel 1.3.1, in version 4.0.7 we updated to mvel 1.3.9. There are several fixes from 1.3.1 to 1.3.9, so I strongly suggest you all update. There are even newer versions of mvel 1.3.x, but the one I personally QA&#39;d and found no problems was 1.3.9.<br>
<br>   Updating is just a matter of replacing the old jar for the new jar in the classpath. There are no API breaks or any other known problem.<br><br>   []s<br>   Edson<br><br><div class="gmail_quote">2009/6/23 Steve Ronderos <span dir="ltr">&lt;<a href="mailto:steve.ronderos@ni.com">steve.ronderos@ni.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><font size="2" face="sans-serif">Edson,</font>
<br><font size="2" face="sans-serif"><br>
Thanks for the quick response!</font>
<br>
<br><font size="2" face="sans-serif">I&#39;m using Drools 4.0.7 and mvel 1.3.1</font>
<br>
<br><font size="2" face="sans-serif">Thanks for the tip about packages and
rulebases.  I&#39;ll make sure to change that in our code.  </font>
<br>
<br><font size="2" face="sans-serif">As far as changing the accumulate to
collect, I can easily work around that selector returning a list of PotentialMatches
instead of Integers.  I made that change and have been unable to create
the ClassCastException since.  I&#39;m still not certain that the problem
is resolved due to its random nature, but I&#39;m hoping that it is patched
enough for now until we can make the rulebase change you mentioned.</font>
<br>
<br><font size="2" face="sans-serif">Thanks for the info about Drools 5.
 I&#39;m currently in the process of converting to Drools 5.</font>
<br>
<br><font size="2" face="sans-serif">You&#39;re right the eval does look odd,
but it is working for the time being.  This rule is in one of the
first features I implemented using Drools, so it is probably not done in
the best way possible.  I&#39;ll keep an eye on it if I do not get this
issue resolved some other way.</font>
<br>
<br><font size="2" face="sans-serif">Thanks again!</font>
<br><font size="2" face="sans-serif"><br>
</font><font size="3">Steve Ronderos </font>
<br>
<br><tt><font size="2"><a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a> wrote on 06/23/2009
11:09:48 AM:<br>
<br>
&gt; [image removed] </font></tt>
<br><tt><font size="2">&gt; <br>
&gt; Re: [rules-users] Class Cast Exception in Drools 4 Generated  <br>
&gt; Accumulate Method</font></tt>
<br><tt><font size="2">&gt; <br>
&gt; Edson Tirelli </font></tt>
<br><tt><font size="2">&gt; <br>
&gt; to:</font></tt>
<br><tt><font size="2">&gt; <br>
&gt; Rules Users List</font></tt>
<br><tt><font size="2">&gt; <br>
&gt; 06/23/2009 11:29 AM</font></tt>
<br><tt><font size="2">&gt; <br>
&gt; Sent by:</font></tt>
<br><tt><font size="2">&gt; <br>
&gt; <a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a></font></tt>
<br><tt><font size="2">&gt; <br>
&gt; Please respond to Rules Users List</font></tt>
<br><div><div></div><div class="h5"><tt><font size="2">&gt; <br>
&gt; <br>
&gt;    Steve,<br>
&gt; <br>
&gt;    What versions of MVEL and Drools are you using?<br>
&gt;    Comments:<br>
&gt; <br>
&gt; * You can not share packages between rulebases. You can share <br>
&gt; rulebases among sessions. So, I strongly advise you to change your
<br>
&gt; application to build the rulebase once, and have the web sessions
<br>
&gt; only create the rule session every time... not the whole rulebase.
<br>
&gt; Since packages have their own classloaders and everytime you create
<br>
&gt; a rulebase you merge such classloaders, the problem might happen <br>
&gt; (CCE) exactly at the time you are creating the rulebase <br>
&gt; concurrently. Drools 5 allows you to share packages, although I <br>
&gt; still prefer to not do it and share only the rulebase.<br>
&gt; <br>
&gt; * You can not use collect in this case, because you are creating a
<br>
&gt; list of $slot, not a list of PotentialMatch. Although, it is <br>
&gt; extremely easy to create an accumulate function for that. Drools 5
<br>
&gt; includes 2 accumulate functions: collectSet and collectList for <br>
&gt; that. If you want, just get the class from Drools 5, fix the imports<br>
&gt; to use the classes from Drools 4 and use it. Except for the <br>
&gt; &quot;imports&quot; you should not have any problem. Your rule would
look like:<br>
&gt; <br>
&gt; <br>
&gt; rule &quot;My Rule&quot; <br>
&gt;     salience 50 <br>
&gt;     dialect &quot;java&quot; <br>
&gt;     no-loop true <br>
&gt;     when <br>
&gt;         $module : Module( selected == false, required
&gt; 1, $size : required )<br>
&gt;         $list : List( ) <br>
&gt;                 from accumulate(
PotentialMatch( module == $module, <br>
&gt; $slot : slot ), <br>
&gt;                    
collectList( $slot ) ) <br>
&gt;         eval( countThem($list, $size) != $module.setMatchCount()
) <br>
&gt;     then <br>
&gt;         modify( $module ) { setMatchCount(countThem($list,
$size)) }; <br>
&gt; end <br>
&gt; <br>
&gt; * Finally, your eval looks odd to me, but anyway, don&#39;t have enough
<br>
&gt; details to advise you on that.<br>
&gt; <br>
&gt; <br>
&gt;     []s<br>
&gt;     Edson<br>
&gt; <br>
</font></tt>
<br><tt><font size="2">&gt; 2009/6/23 Steve Ronderos &lt;<a href="mailto:steve.ronderos@ni.com" target="_blank">steve.ronderos@ni.com</a>&gt;</font></tt>
<br><tt><font size="2">&gt; <br>
&gt; Hi Rules Users, <br>
&gt; <br>
&gt; I&#39;m experiencing an issue with a Drools 4.0.7 rule. <br>
&gt; <br>
&gt; Here is a clip of the exception that is thrown: <br>
&gt; <br>
&gt; Caused by: org.mvel.CompileException: cannot invoke method <br>
&gt;         at org.mvel.optimizers.impl.refl.MethodAccessor.getValue<br>
&gt; (MethodAccessor.java:54) <br>
&gt;         at org.mvel.optimizers.impl.refl.VariableAccessor.getValue<br>
&gt; (VariableAccessor.java:39) <br>
&gt;         at <br>
&gt; org.mvel.ast.VariableDeepPropertyNode.getReducedValueAccelerated<br>
&gt; (VariableDeepPropertyNode.java:22) <br>
&gt;         at org.mvel.ast.PropertyASTNode.getReducedValueAccelerated<br>
&gt; (PropertyASTNode.java:21) <br>
&gt;         at org.mvel.MVELRuntime.execute(MVELRuntime.java:90)
<br>
&gt;         at org.mvel.CompiledExpression.getValue(CompiledExpression.java:111)
<br>
&gt;         at org.mvel.MVEL.executeExpression(MVEL.java:235)
<br>
&gt;         at org.drools.base.mvel.MVELConsequence.evaluate<br>
&gt; (MVELConsequence.java:48) <br>
&gt;         at org.drools.common.DefaultAgenda.fireActivation<br>
&gt; (DefaultAgenda.java:554) <br>
&gt;         ... 80 more <br>
&gt; Caused by: java.lang.reflect.InvocationTargetException <br>
&gt;         at sun.reflect.GeneratedMethodAccessor412.invoke(Unknown
Source) <br>
&gt;         at sun.reflect.DelegatingMethodAccessorImpl.invoke<br>
&gt; (DelegatingMethodAccessorImpl.java:25) <br>
&gt;         at java.lang.reflect.Method.invoke(Method.java:585)
<br>
&gt;         at org.mvel.optimizers.impl.refl.MethodAccessor.getValue<br>
&gt; (MethodAccessor.java:46) <br>
&gt;         ... 88 more <br>
&gt; Caused by: org.drools.RuntimeDroolsException: <br>
&gt; java.lang.ClassCastException: com.demo.Rule_My_Rule_0$Accumulate0
<br>
&gt;         at org.drools.rule.Accumulate.accumulate(Accumulate.java:131)
<br>
&gt;         at org.drools.reteoo.AccumulateNode.modifyTuple<br>
&gt; (AccumulateNode.java:352) <br>
&gt;         at org.drools.reteoo.AccumulateNode.assertObject<br>
&gt; (AccumulateNode.java:248) <br>
&gt;         at <br>
&gt; org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject<br>
&gt; (CompositeObjectSinkAdapter.java:318) <br>
&gt;         at org.drools.reteoo.ObjectTypeNode.assertObject<br>
&gt; (ObjectTypeNode.java:162) <br>
&gt;         at org.drools.reteoo.Rete.assertObject(Rete.java:175)
<br>
&gt;         at org.drools.reteoo.ReteooRuleBase.assertObject<br>
&gt; (ReteooRuleBase.java:192) <br>
&gt;         at org.drools.reteoo.ReteooWorkingMemory.doInsert<br>
&gt; (ReteooWorkingMemory.java:71) <br>
&gt;         at org.drools.common.AbstractWorkingMemory.insert<br>
&gt; (AbstractWorkingMemory.java:911) <br>
&gt;         at org.drools.common.AbstractWorkingMemory.insert<br>
&gt; (AbstractWorkingMemory.java:883) <br>
&gt;         at org.drools.base.DefaultKnowledgeHelper.insert<br>
&gt; (DefaultKnowledgeHelper.java:67) <br>
&gt;         at org.drools.base.DefaultKnowledgeHelper.insert<br>
&gt; (DefaultKnowledgeHelper.java:61) <br>
&gt;         ... 92 more <br>
&gt; Caused by: java.lang.ClassCastException: com.demo.Rule_My_Rule_0$Accumulate0
<br>
&gt;         at com.demo.Rule_My_Rule_0Accumulate0Invoker.accumulate<br>
&gt; (Rule_My_Rule_0Accumulate0Invoker.java:43) <br>
&gt;         at org.drools.rule.Accumulate.accumulate(Accumulate.java:123)
<br>
&gt;         ... 103 more <br>
&gt; <br>
&gt; The actually rule name and package are a lot longer, I changed them
<br>
&gt; here for brevity and because I don&#39;t believe the names themselves
<br>
&gt; are relevant. <br>
&gt; <br>
&gt; This exception is being thrown intermittently when this rule, which
<br>
&gt; contains an accumulate function is called.  I say intermittently
<br>
&gt; because it does not happen every time the rule is run.  As far
as I <br>
&gt; can tell the ClassCastExceptions only happens when the computer that<br>
&gt; the rules are running on is under load. <br>
&gt; <br>
&gt; A few more details before I post the rule itself.  The rule base
<br>
&gt; that I am building consists of 2 drl files.  Both of the files
have <br>
&gt; the same package declaration at the top.  The 2 packages are
built <br>
&gt; separately using PackageBuilder then combined using <br>
&gt; RuleBase.addPackage() on both packages.  Also, I&#39;m not sure if
this <br>
&gt; is relevant, but this scenario takes place in a web application <br>
&gt; where the two package objects are only built once (for performance)
<br>
&gt; but each user session creates a new RuleBase and adds the packages.
<br>
&gt;  The individual sessions then create stateful sessions from the
rule base. <br>
&gt; <br>
&gt; This is the rule that I believe is causing the issue. <br>
&gt; <br>
&gt; rule &quot;My Rule&quot; <br>
&gt;     salience 50 <br>
&gt;     dialect &quot;java&quot; <br>
&gt;     no-loop true <br>
&gt;     when <br>
&gt;         $module : Module( selected == false, required
&gt; 1, $size : required )<br>
&gt;         $list : ArrayList( ) <br>
&gt;                 from accumulate(
PotentialMatch( module == $module, <br>
&gt; $slot : slot ), <br>
&gt;                    
init( List result = new ArrayList(); ), <br>
&gt;                    
action( result.add($slot); ), <br>
&gt;                    
reverse( result.remove((Integer)$slot ); ), <br>
&gt;                    
result( result ) ) <br>
&gt;         eval( countThem($list, $size) != $module.setMatchCount()
) <br>
&gt;     then <br>
&gt;         modify( $module ) { setMatchCount(countThem($list,
$size)) }; <br>
&gt; end <br>
&gt; <br>
&gt; As I&#39;m typing this I realize that there is another way to write this<br>
&gt; rule using collect.  I&#39;m not sure why it was written this way,
but <br>
&gt; since I have already come this far, has anyone had any experience
<br>
&gt; with the Drools 4 generated code throwing ClassCastExceptions? <br>
&gt; <br>
&gt; Thanks, <br>
&gt; <br>
&gt; Steve Ronderos<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
&gt; </font></tt><a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank"><tt><font size="2">https://lists.jboss.org/mailman/listinfo/rules-users</font></tt></a><tt><font size="2"><br>
</font></tt>
<br><tt><font size="2">&gt; <br>
&gt; <br>
&gt; <br>
&gt; -- <br>
&gt;  Edson Tirelli<br>
&gt;  JBoss Drools Core Development<br>
&gt;  JBoss by Red Hat @ </font></tt><a href="http://www.jboss.com" target="_blank"><tt><font size="2">www.jboss.com</font></tt></a><tt><font size="2"><br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
&gt; </font></tt><a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank"><tt><font size="2">https://lists.jboss.org/mailman/listinfo/rules-users</font></tt></a><tt><font size="2"><br>
</font></tt></div></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>  Edson Tirelli<br>  JBoss Drools Core Development<br>  JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>