Use of setFirstResult / setMaxResults can lead to a list with negative capacity (John Griffin)

Description

I did this query:

fullTextQuery.setFirstResult(sr.getOffset());
fullTextQuery.setMaxResults(sr.getLength());
List results = fullTextQuery.list();

sr.getOffset() and sr.getLength() are pagination parameters. They happened to be carried from another query as a session properties (not the right thing to do here but it happened). In my case offset was 10 and length was 10. The new search result is empty, so these lines of code in FullTextQueryImpl gave a negative capacity for list exception:

int first = first();
int max = max( first, hits );
Session sess = (Session) this.session;
List<EntityInfo> infos = new ArrayList<EntityInfo>( max - first + 1);

because max=-1 and first=10. Would it be nice if a check is done before assign List capacities?

Activity

Show:
Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Created June 26, 2007 at 4:19 PM
Updated November 13, 2008 at 6:08 PM
Resolved July 29, 2007 at 6:33 PM