This is an automated email from the ASF dual-hosted git repository. paulk-asert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/groovy.git
commit fe8a7df706527909154381e6b8045c7c2e91fcf1 Author: Paul King <[email protected]> AuthorDate: Sat May 23 07:26:29 2026 +1000 minor refactor: improved robustness/better error message for empty aggregates with partitionPoint --- .../groovy/runtime/ArrayGroovyMethods.java | 28 ++++++++++++++++++++++ .../groovy/runtime/DefaultGroovyMethods.java | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java index 17c1a41a2c..efa2aeb979 100644 --- a/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java +++ b/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java @@ -6921,6 +6921,8 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * assert arr.partitionPoint{ it <= 100 } == arr.size() * // for no match condition * assert arr.partitionPoint{ it <= 0 } == 0 + * // empty input + * assert (new Integer[0]).partitionPoint{ it < 4 } == 0 * </pre> * * @param self a groovy arr @@ -6929,6 +6931,8 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * @since 5.0.0 */ public static <T> int partitionPoint(T[] self, Predicate<? super T> condition) { + Objects.requireNonNull(self); + if (self.length == 0) return 0; return partitionPoint(self, new IntRange(true, 0, self.length - 1), condition); } @@ -6999,6 +7003,8 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * assert arr.partitionPoint{ it <= 100 } == arr.size() * // for no match condition * assert arr.partitionPoint{ it <= 0 } == 0 + * // empty input + * assert (new char[0]).partitionPoint{ it < 4 } == 0 * </pre> * * @param self a groovy arr @@ -7007,6 +7013,8 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * @since 5.0.0 */ public static int partitionPoint(char[] self, IntPredicate condition) { + Objects.requireNonNull(self); + if (self.length == 0) return 0; return partitionPoint(self, new IntRange(true, 0, self.length - 1), condition); } @@ -7077,6 +7085,8 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * assert arr.partitionPoint{ it <= 100 } == arr.size() * // for no match condition * assert arr.partitionPoint{ it <= 0 } == 0 + * // empty input + * assert (new short[0]).partitionPoint{ it < 4 } == 0 * </pre> * * @param self a groovy arr @@ -7085,6 +7095,8 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * @since 5.0.0 */ public static int partitionPoint(short[] self, IntPredicate condition) { + Objects.requireNonNull(self); + if (self.length == 0) return 0; return partitionPoint(self, new IntRange(true, 0, self.length - 1), condition); } @@ -7155,6 +7167,8 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * assert arr.partitionPoint{ it <= 100 } == arr.size() * // for no match condition * assert arr.partitionPoint{ it <= 0 } == 0 + * // empty input + * assert (new int[0]).partitionPoint{ it < 4 } == 0 * </pre> * * @param self a groovy arr @@ -7163,6 +7177,8 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * @since 5.0.0 */ public static int partitionPoint(int[] self, IntPredicate condition) { + Objects.requireNonNull(self); + if (self.length == 0) return 0; return partitionPoint(self, new IntRange(true, 0, self.length - 1), condition); } @@ -7233,6 +7249,8 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * assert arr.partitionPoint{ it <= 100 } == arr.size() * // for no match condition * assert arr.partitionPoint{ it <= 0 } == 0 + * // empty input + * assert (new long[0]).partitionPoint{ it < 4 } == 0 * </pre> * * @param self a groovy arr @@ -7241,6 +7259,8 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * @since 5.0.0 */ public static int partitionPoint(long[] self, LongPredicate condition) { + Objects.requireNonNull(self); + if (self.length == 0) return 0; return partitionPoint(self, new IntRange(true, 0, self.length - 1), condition); } @@ -7311,6 +7331,8 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * assert arr.partitionPoint{ it <= 100 } == arr.size() * // for no match condition * assert arr.partitionPoint{ it <= 0 } == 0 + * // empty input + * assert (new float[0]).partitionPoint{ it < 4 } == 0 * </pre> * * @param self a groovy arr @@ -7319,6 +7341,8 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * @since 5.0.0 */ public static int partitionPoint(float[] self, DoublePredicate condition) { + Objects.requireNonNull(self); + if (self.length == 0) return 0; return partitionPoint(self, new IntRange(true, 0, self.length - 1), condition); } @@ -7389,6 +7413,8 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * assert arr.partitionPoint{ it <= 100 } == arr.size() * // for no match condition * assert arr.partitionPoint{ it <= 0 } == 0 + * // empty input + * assert (new double[0]).partitionPoint{ it < 4 } == 0 * </pre> * * @param self a groovy arr @@ -7397,6 +7423,8 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * @since 5.0.0 */ public static int partitionPoint(double[] self, DoublePredicate condition) { + Objects.requireNonNull(self); + if (self.length == 0) return 0; return partitionPoint(self, new IntRange(true, 0, self.length - 1), condition); } diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java index 4fc75e7b5e..98c080b582 100644 --- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java +++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java @@ -11664,6 +11664,8 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport { * // predicate of reverse logic examples: * assert [7, 6, 5, 4, 4, 3, 3, 2, 1].partitionPoint{ it > 4 } == 3 * assert [7, 6, 5, 4, 4, 3, 3, 2, 1].partitionPoint{ it >= 4 } == 5 + * // empty input + * assert [].partitionPoint{ it < 4 } == 0 * </pre> * * @param self a groovy list @@ -11672,6 +11674,8 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport { * @since 5.0.0 */ public static <T> int partitionPoint(List<T> self, Predicate<? super T> condition) { + Objects.requireNonNull(self); + if (self.isEmpty()) return 0; return partitionPoint(self, new IntRange(true, 0, self.size() - 1), condition); }
