SCXML-275 <content> expression evaluation must fallback to empty string on error...
authorAte Douma <ate@apache.org>
Sun, 17 Dec 2017 22:52:45 +0000 (23:52 +0100)
committerAte Douma <ate@apache.org>
Sun, 17 Dec 2017 22:52:45 +0000 (23:52 +0100)
src/main/java/org/apache/commons/scxml2/model/Final.java
src/main/java/org/apache/commons/scxml2/model/Invoke.java
src/main/java/org/apache/commons/scxml2/model/Send.java

index 28a8063..04aaa16 100644 (file)
@@ -90,7 +90,18 @@ public class Final extends EnterableState {
                 Context ctx = exctx.getScInstance().getGlobalContext();
                 if (content != null) {
                     if (content.getExpr() != null) {
-                        result = eval.cloneData(eval.eval(ctx, content.getExpr()));
+                        Object evalResult = null;
+                        try {
+                            evalResult = eval.eval(ctx, content.getExpr());
+                        } catch (SCXMLExpressionException e) {
+                            exctx.getInternalIOProcessor().addEvent(new EventBuilder(TriggerEvent.ERROR_EXECUTION,
+                                    TriggerEvent.ERROR_EVENT).build());
+                            exctx.getErrorReporter().onError(ErrorConstants.EXPRESSION_ERROR,
+                                    "Failed to evaluate <donedata> <content> expression due to error: "+ e.getMessage()
+                                            + ", Using empty value instead.", getParent());
+                            evalResult = "";
+                        }
+                        result = eval.cloneData(evalResult);
                     } else if (content.getValue() != null) {
                         result = content.getValue();
                     }
index b7ccf37..a4a0d21 100644 (file)
@@ -401,7 +401,16 @@ public class Invoke extends Action implements ContentContainer, ParamsContainer
             Object contentValue = null;
             if (src == null && content != null) {
                 if (content.getExpr() != null) {
-                    contentValue = eval.eval(ctx, content.getExpr());
+                    try {
+                        contentValue = eval.eval(ctx, content.getExpr());
+                    } catch (SCXMLExpressionException e) {
+                        exctx.getInternalIOProcessor().addEvent(new EventBuilder(TriggerEvent.ERROR_EXECUTION,
+                                TriggerEvent.ERROR_EVENT).build());
+                        exctx.getErrorReporter().onError(ErrorConstants.EXPRESSION_ERROR,
+                                "Failed to evaluate <invoke> <content> expression due to error: "+ e.getMessage()
+                                        + ", Using empty value instead.", getParent());
+                        contentValue = "";
+                    }
                 } else if (content.getValue() != null) {
                     contentValue = content.getValue();
                 }
index 1ff8a7c..f38a0b4 100644 (file)
@@ -24,9 +24,12 @@ import java.util.Map;
 import org.apache.commons.scxml2.ActionExecutionContext;
 import org.apache.commons.scxml2.Context;
 import org.apache.commons.scxml2.Evaluator;
+import org.apache.commons.scxml2.EventBuilder;
 import org.apache.commons.scxml2.SCXMLExpressionException;
 import org.apache.commons.scxml2.SCXMLIOProcessor;
 import org.apache.commons.scxml2.SCXMLSystemContext;
+import org.apache.commons.scxml2.TriggerEvent;
+import org.apache.commons.scxml2.semantics.ErrorConstants;
 
 /**
  * The class in this SCXML object model that corresponds to the
@@ -431,7 +434,18 @@ public class Send extends Action implements ContentContainer, ParamsContainer {
         }
         else if (content != null) {
             if (content.getExpr() != null) {
-                payload = eval.cloneData(eval.eval(ctx, content.getExpr()));
+                Object evalResult = null;
+                try {
+                    evalResult = eval.eval(ctx, content.getExpr());
+                } catch (SCXMLExpressionException e) {
+                    exctx.getInternalIOProcessor().addEvent(new EventBuilder(TriggerEvent.ERROR_EXECUTION,
+                            TriggerEvent.ERROR_EVENT).build());
+                    exctx.getErrorReporter().onError(ErrorConstants.EXPRESSION_ERROR,
+                            "Failed to evaluate <send> <content> expression due to error: "+ e.getMessage()
+                                    + ", Using empty value instead.", getParent());
+                    evalResult = "";
+                }
+                payload = eval.cloneData(evalResult);
             } else if (content.getValue() != null) {
                 payload = content.getValue();
             }