3 Replies Latest reply on Apr 9, 2012 5:54 PM by Peter Vieth

    ClassCastException on .splitNode().constraint()

    Connie Yang Newbie

      Hi,

       

      I'm using jbpm-flow-5.2.0-SNAPSHOT.jar and got a ClassCastException below with the following Drools flow snippet.  I've tried mvel dialet as well and got the same error.

       

       

                          .splitNode(1010).type(Split.TYPE_XOR).name("splitOnShouldActivate")

                               .constraint(305, "should activate", "code", "Java",

                                  "(Boolean)(context.getVariable(\"shouldActivate\")) == Boolean.TRUE")

                               .constraint(2000, "should not activate", "code", "Java",

                                  "(Boolean)(context.getVariable(\"shouldActivate\")) == Boolean.FALSE")

                          .done

       

       

       

       

      Exception in thread "main" java.lang.ClassCastException: org.jbpm.workflow.core.impl.ConstraintImpl incompatible with org.jbpm.process.instance.impl.ConstraintEvaluator

          at org.jbpm.workflow.instance.node.SplitInstance.internalTrigger(SplitInstance.java:69)

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:185)

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:150)

          at org.jbpm.workflow.instance.node.ActionNodeInstance.triggerCompleted(ActionNodeInstance.java:55)

          at org.jbpm.workflow.instance.node.ActionNodeInstance.internalTrigger(ActionNodeInstance.java:51)

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:185)

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:150)

          at org.jbpm.workflow.instance.impl.ExtendedNodeInstanceImpl.triggerCompleted(ExtendedNodeInstanceImpl.java:47)

          at org.jbpm.workflow.instance.node.StateBasedNodeInstance.triggerCompleted(StateBasedNodeInstance.java:162)

          at org.jbpm.workflow.instance.node.StateBasedNodeInstance.triggerCompleted(StateBasedNodeInstance.java:143)

          at org.jbpm.workflow.instance.node.SubProcessNodeInstance.internalTrigger(SubProcessNodeInstance.java:130)

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:185)

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:150)

          at org.jbpm.workflow.instance.node.ActionNodeInstance.triggerCompleted(ActionNodeInstance.java:55)

          at org.jbpm.workflow.instance.node.ActionNodeInstance.internalTrigger(ActionNodeInstance.java:51)

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:185)

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:150)

          at org.jbpm.workflow.instance.node.StartNodeInstance.triggerCompleted(StartNodeInstance.java:49)

          at org.jbpm.workflow.instance.node.StartNodeInstance.internalTrigger(StartNodeInstance.java:41)

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)

          at org.jbpm.workflow.instance.node.CompositeNodeInstance.internalTrigger(CompositeNodeInstance.java:106)

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)

          at org.jbpm.workflow.instance.node.ForEachNodeInstance$ForEachSplitNodeInstance.internalTrigger(ForEachNodeInstance.java:97)

       

      Thanks in advance.


        • 1. Re: ClassCastException on .splitNode().constraint()
          Tihomir Surdilovic Master

          Hi Connie, could you please provide a reproducible stand-alone test case so we can test and raise a Jira if this is a bug indeed?

           

          Thank you.

          • 2. Re: ClassCastException on .splitNode().constraint()
            Connie Yang Newbie

            Hi Tihomir,

             

            Thanks for your reply!  Attached is a standalone test case that consistently surfaces the exception above.

             

            We're using the following libraries

            • jbpm-flow-5.2.0-SNAPSHOT.jar
            • jbpm-bpmn2-5.2.0-SNAPSHOT.jar
            • drools-core-5.3.0-SNAPSHOT.jar
            • knowledge-api-5.3.0-SNAPSHOT.jar

             

            Thanks,

            Connie

            • 3. Re: ClassCastException on .splitNode().constraint()
              Peter Vieth Newbie

              [Note: I have updated the code below as it didn't pass the process instance to the MVEL evaluation!  You may wish to rename processInstance to kContext to match some of the example code out there]

              Was there ever any progress on this?  I'm using 5.2.0.M1 and ran across the same issue.  Trouble is that ConstraintImpl doesn't have an evaluate() function, so it can't be cast to ConstraintEvaluator in SplitInstance (forget the exact line numbers, but there are in the code blocks for splits of type XOR and OR).  I made my own EvalConstraintImpl class which  implements ConstraintEvaluator and extends ConstraintImpl.  It contains only the evaluate function, where I just get the constraint string and return MVEL.eval(constraint_string). 

               

              Really basic and ugly:

               

               

              import org.drools.definition.process.Connection;

              import org.jbpm.process.instance.impl.ConstraintEvaluator;

              import org.jbpm.workflow.core.Constraint;

              import org.jbpm.workflow.core.impl.ConstraintImpl;

              import org.jbpm.workflow.instance.node.SplitInstance;

              import java.io.Serializable;

               

               

              import org.drools.definition.process.Connection;

              import org.drools.runtime.process.WorkflowProcessInstance;

              import org.drools.runtime.rule.impl.InternalAgenda;

              import org.jbpm.process.instance.ProcessInstance;

              import org.jbpm.workflow.core.Constraint;

              import org.jbpm.workflow.core.Node;

              import org.jbpm.workflow.instance.node.SplitInstance;

              import org.mvel2.MVEL;

               

               

              public class EvaluatableConstraintImpl extends ConstraintImpl implements

                                  Constraint, ConstraintEvaluator, Serializable {

               

                        private static final long  serialVersionUID = 510l;

               

                        public boolean evaluate(SplitInstance instance, Connection conn, Constraint constraint) {

                                  WorkflowProcessInstance processInstance = instance.getProcessInstance();

               

                                  HashMap<String, Object> vars = new HashMap<String, Object>();

                                 vars.put("processInstance", instance.getProcessInstance());

               

                                  return (Boolean) MVEL.eval(constraint.getConstraint());

                        }

               

               

              }