private static void checkNesting ( final BooleanExpression expression , final List < BooleanExpression > visitedExpressions ) { if ( visitedExpressions . contains ( expression ) ) { // Unfortunately, we can't give much more information - even calling toString() will overflow the stack. throw new SyntaxException ( "An expression can not contain itself." ) ; } visitedExpressions . add ( expression ) ; if ( expression instanceof GroupExpression ) { GroupExpression group = ( GroupExpression ) expression ; for ( BooleanExpression operand : group . getOperands ( ) ) { checkNesting ( operand , visitedExpressions ) ; } } }
Checks nesting of expressions to ensure we don t end up in an infinite recursive loop during evaluation .