Long "in" lists in queries results in a Java stack overflow exception.

Description

With Hibernate 320ga a long "in" list can result in a stack overflow error during the parsing stage. For example, a query element like

where x in (:x)

or a manually constructed

where x in (1,2,3 .....)

can generate a stack overflow if the number of elements referenced by x exceeds a number dependent upon the amount of available stack space. For many JVMs, the limit is between 9,000 and 10,000 assuming a relatively empty stack at the point of query execution. We have applications which occasionally use lists several times this size.

The stack overflow occurs in org.hibernate.hql.ast.util.NodeTraverser which uses a recursive algorithm to walk a parse tree. Long "in" lists generate a subtree of depth about equal to the number of elements in the list. A sufficiently long list results in a stack overflow when NodeTraverser's internal method visitDepthFirst calls itself too many times.

The solution is to replace the recursive tree walking strategy with an iterative one that does not use up stack space. I am attaching the source for a replacement version of . NodeTraverser which implements the iterative tree walking method.

Attachments

1

Activity

Show:

Laurence Pascall August 31, 2018 at 3:53 PM

Still seeing this issue with 5.2.9 final

sawyna October 30, 2017 at 11:16 AM

This error still seems to happen. Is there any reason why this issue is closed and the test is marked ignored?

Steve Ebersole March 24, 2015 at 4:28 PM

for now I disabled the test with @Ignore.

Steve Ebersole March 24, 2015 at 4:24 PM

Sorry, I have no idea about the solution either. Strong? FWIW, this is back when trying to build with Java 8...

Carlos David Sánchez November 18, 2011 at 9:43 PM

Sorry, I mean hibernate 3.2.7 GA.

Fixed

Details

Assignee

Reporter

Original estimate

Time tracking

No time logged8h remaining

Components

Affects versions

Priority

Created October 20, 2006 at 9:07 PM
Updated August 31, 2018 at 3:53 PM
Resolved December 29, 2009 at 10:16 PM