4 Replies Latest reply on Jan 27, 2011 8:41 PM by milnauf

    Transition rule EL Expression fails [Solved]

    dondragon2

      I am using the default expression language to evaluate the rules for my transitions. But, I am getting the following exception each time it tries to process a rule in my decision node.

       

       

      org.jbpm.api.JbpmException: expression condition ' #{response['resultSet'] != null && response['resultSet'][0][3] > 0}' did not return a boolean:  true
              at org.jbpm.pvm.internal.model.ExpressionCondition.evaluate(ExpressionCondition.java:45)
              at org.jbpm.jpdl.internal.activity.DecisionConditionActivity.findTransitionUsingConditions(DecisionConditionActivity.java:62)

       

       

      org.jbpm.api.JbpmException: expression condition ' #{response['resultSet'] != null && response['resultSet'][0][3] > 0}' did not return a boolean:  true

              at org.jbpm.pvm.internal.model.ExpressionCondition.evaluate(ExpressionCondition.java:45)

              at org.jbpm.jpdl.internal.activity.DecisionConditionActivity.findTransitionUsingConditions(DecisionConditionActivity.java:62)

       

       

      Why is result a string instead of a boolean?

      How can I get around this?

        • 1. Re: Transition rule EL Expression fails
          rebody

          Hi Donald,

           

            Which verion of jbpm did you used?

           

            Could you show us a testcase which could re-produce this problem.  This will be helpful for investigating it.

           

            Thank you very much.

          • 2. Re: Transition rule EL Expression fails
            dondragon2

            I am using version 4.4

            The issue is in the ExpressionCondition class

             

            public boolean evaluate(OpenExecution execution) {

                    Object result = Expression.create(expression, language).evaluate();

                    if (result instanceof Boolean) {

                        return ((Boolean) result).booleanValue();

                    }

                         throw new JbpmException("expression condition '" + expression + "' did not return a boolean: " + result);

                }

             

            Apparently the value that is returned by the Expression.create is a String " true " which would fail based on the conditions above. I had to modify the code to reflect the following.

            public boolean evaluate(OpenExecution execution) {

                    Object result = Expression.create(expression, language).evaluate();

                    if (result instanceof Boolean) {

                        return ((Boolean) result).booleanValue();

                    }

                    if (result instanceof String) {

                        if(result == null)

                            return false;

                        return Boolean.valueOf(((String) result).trim());

                    }

                    throw new JbpmException("expression condition '" + expression + "' did not return a boolean: " + result);

                }

            After doing that it is evaluated properly. This an issue that needs to resolved in the official distribution.

            public boolean evaluate(OpenExecution execution) {
                    Object result = Expression.create(expression, language).evaluate();
                    if (result instanceof Boolean) {
                        return ((Boolean) result).booleanValue();
                    }
                    if (result instanceof String) {
                        if(result == null)
                            return false;
                        return Boolean.valueOf(((String) result).trim());
                    }
                    throw new JbpmException("expression condition '" + expression + "' did not return a boolean: " + result);
                }
            • 3. Re: Transition rule EL Expression fails [Solved]
              rebody

              Hi Donald.

               

                 Unfortunately, I cannot reproduce this problem,  I upload a testcase for this scenario.  Could you have a look at it?  Thank you very much.

               

              http://anonsvn.jboss.org/repos/jbpm/jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/UelExpressionTest.java

              • 4. Re: Transition rule EL Expression fails [Solved]
                milnauf

                Hello,

                I running into problems when I try evaluating an expression during runtime (yeah - using internal APIs  :s ). What I'm doing is essentially try to find possible execution path using transition's condition.
                The problem is that the method org.jbpm.pvm.internal.model.ExpressionCondition.evaluate(OpenExecution execution) - invokes evaluate() on created expression - rather than evaluate(execution). The problem is that the execution variables are not found - because in the subsequent call to JbpmElFactoryImpl.createCompositeResolver - if the scopeInstance is null - which it is in this case - the JbpmVariableElResolver is not added.

                So a cosmetic change of the org.jbpm.pvm.internal.model.ExpressionCondition evaluate to invoke evaluate with execution parameter rather than without it - should fix the problem. Unless of course there's a good reason for not passing current execution.

                 

                At the bottom I attach a stacktrace for the error that I'm getting -> resulting directly from not using the OpenExecution to evaluate the expression.

                 

                The resulting code would be similar to the below:

                 

                public class org.jbpm.pvm.internal.model.ExpressionCondition {

                public boolean evaluate(OpenExecution execution) {

                    Object result = Expression.create(expression, language).evaluate(execution);

                    if (result instanceof Boolean) {

                      return ((Boolean) result).booleanValue();

                    }

                    throw new JbpmException("expression condition '" + expression + "' did not return a boolean: "+result);

                  }

                 

                  ...

                }

                 

                Stack trace:

                javax.el.PropertyNotFoundException: Cannot resolve identifier 'task1'

                    at de.odysseus.el.tree.impl.ast.AstIdentifier.eval(AstIdentifier.java:86)

                    at de.odysseus.el.tree.impl.ast.AstEval.eval(AstEval.java:51)

                    at de.odysseus.el.tree.impl.ast.AstNode.getValue(AstNode.java:28)

                    at de.odysseus.el.TreeValueExpression.getValue(TreeValueExpression.java:122)

                    at org.jbpm.pvm.internal.el.UelValueExpression.evaluateInScope(UelValueExpression.java:52)

                    at org.jbpm.pvm.internal.el.Expression.evaluate(Expression.java:108)

                    at org.jbpm.pvm.internal.model.ExpressionCondition.evaluate(ExpressionCondition.java:41)

                ...

                 

                caused by a call to:

                boolean followPath = transition.getCondition().evaluate(openExecution);