Skip to content

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

emfanitek opened this Issue Apr 5, 2013 · 0 comments

1 participant


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

DomainObject.withCreteria {
java.lang.IndexOutOfBoundsException: toIndex = 15
    at java.util.SubList.<init>(
    at java.util.RandomAccessSubList.<init>(
    at java.util.AbstractList.subList(
    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)]

Should be

    def _maxAndOffset(ls){
        if(_offset) ls = ls[_offset..-1]
        if(_maxRes) ls = ls[0..(Math.min(_maxRes,ls.size())-1)]
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.