Short-circuit logical expression in ExpressionInterpreter
@@ -857,10 +857,16 @@ public class ExpressionInterpreter
protected Object visitLogicalBinaryExpression(LogicalBinaryExpression node, Object context)
{
Object left = process(node.getLeft(), context);
- Object right = process(node.getRight(), context);
+ Object right;
switch (node.getType()) {
case AND: {
+ if (Boolean.FALSE.equals(left)) {
+ return false;
+ }
+
+ right = process(node.getRight(), context);
+
if (Boolean.FALSE.equals(left) || Boolean.TRUE.equals(right)) {
return left;
}
@@ -871,6 +877,12 @@ public class ExpressionInterpreter
break;
}
case OR: {
+ if (Boolean.TRUE.equals(left)) {
+ return true;
+ }
+
+ right = process(node.getRight(), context);
+
if (Boolean.TRUE.equals(left) || Boolean.FALSE.equals(right)) {
return left;
}
@@ -880,6 +892,8 @@ public class ExpressionInterpreter
}
break;
}
+ default:
+ throw new IllegalStateException("Unknown LogicalBinaryExpression#Type");
}
if (left == null && right == null) {
