Skip to content

maxResults criterion fails if maxresults > ls.size() #6

Closed
emfanitek opened this Issue Apr 5, 2013 · 0 comments

1 participant

@emfanitek

I get the following stack trace, if the total potential results are smaller than the maxresults parameter:

DomainObject.withCreteria {
            maxResults(15)
}
java.lang.IndexOutOfBoundsException: toIndex = 15
    at java.util.SubList.<init>(AbstractList.java:602)
    at java.util.RandomAccessSubList.<init>(AbstractList.java:758)
    at java.util.AbstractList.subList(AbstractList.java:468)
    at plastic.criteria.PlasticCriteria._maxAndOffset(PlasticCriteria.groovy:243)
    at plastic.criteria.PlasticCriteria.list(PlasticCriteria.groovy:238)
    at plastic.criteria.PlasticCriteria.mockCriteria_closure20(PlasticCriteria.groovy:61)

I think that following method has a bug:

    def _maxAndOffset(ls){
        if(_offset) ls = ls[_offset..-1]
        if(_maxRes) ls = ls[0..(_maxRes -1)]
        ls
    }

Should be

    def _maxAndOffset(ls){
        if(_offset) ls = ls[_offset..-1]
        if(_maxRes) ls = ls[0..(Math.min(_maxRes,ls.size())-1)]
        ls
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.