From 95e10ad81d672202240ef09792478a16f1e63779 Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Tue, 29 Dec 2009 23:21:44 +0000 Subject: [PATCH] HHH-2166 Long 'in' lists in queries results in a Java stack overflow exception. git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18356 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../hibernate/hql/ast/util/NodeTraverser.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/hibernate/hql/ast/util/NodeTraverser.java b/core/src/main/java/org/hibernate/hql/ast/util/NodeTraverser.java index 2dc99aca09..b37a7667b3 100644 --- a/core/src/main/java/org/hibernate/hql/ast/util/NodeTraverser.java +++ b/core/src/main/java/org/hibernate/hql/ast/util/NodeTraverser.java @@ -46,7 +46,7 @@ public class NodeTraverser { public NodeTraverser( VisitationStrategy strategy ) { this.strategy = strategy; } - + /** * Traverse the AST tree depth first. * @@ -63,20 +63,26 @@ public class NodeTraverser { throw new IllegalArgumentException( "node to traverse cannot be null!" ); } - AST node = ast.getFirstChild(); + visitDepthFirst( ast.getFirstChild() ); + } + + private void visitDepthFirst(AST ast){ + if(ast==null){ + return; + } Stack stack = new Stack(); - if ( node != null ) { - stack.push( node ); + if ( ast != null ) { + stack.push( ast ); while (!stack.empty()) { - node = (AST) stack.pop(); - strategy.visit( node ); - if ( node.getFirstChild() != null ) { - stack.push( node.getFirstChild() ); - } - if ( node.getNextSibling() != null ) { - stack.push( node.getNextSibling() ); - } + ast = (AST) stack.pop(); + strategy.visit( ast ); + if ( ast.getNextSibling() != null ) + stack.push( ast.getNextSibling() ); + if ( ast.getFirstChild() != null ) + stack.push( ast.getFirstChild() ); } } } + + }