You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/04/12 09:23:29 UTC

[groovy] 12/25: GROOVY-9649: Fix IntRange size being negative on some occasions

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 1a8f109b6bfc073dc81bf4ea63a3b0878aa70360
Author: Eerik Voimanen <ee...@tuni.fi>
AuthorDate: Wed Apr 7 16:39:32 2021 +0300

    GROOVY-9649: Fix IntRange size being negative on some occasions
---
 src/main/java/groovy/lang/IntRange.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/main/java/groovy/lang/IntRange.java b/src/main/java/groovy/lang/IntRange.java
index c11fd94..7a701ad 100644
--- a/src/main/java/groovy/lang/IntRange.java
+++ b/src/main/java/groovy/lang/IntRange.java
@@ -362,7 +362,8 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer>, S
 
     @Override
     public int size() {
-        return getTo() - getFrom() + 1;
+        // If fully exclusive and borders are one apart, the size would be negative, take that into account
+        return Math.max(getTo() - getFrom() + 1, 0);
     }
 
     @Override