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?

Environment

None

Status

Assignee

John Griffin

Reporter

whate

Labels

None

Suitable for new contributors

None

Pull Request

None

Feedback Requested

None

Components

Fix versions

Affects versions

3.0.0.beta3

Priority

Minor