Skip to content

Commit 7c934ad

Browse files
authored
Reject null BitonicSort input explicitly (#7550)
Update BitonicSort.java Added a descriptive null-input validation and a focused regression test.
1 parent 1f4e2f8 commit 7c934ad

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/main/java/com/thealgorithms/sorts/BitonicSort.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ private enum Direction {
2121
*/
2222
@Override
2323
public <T extends Comparable<T>> T[] sort(T[] array) {
24+
if (array == null) {
25+
throw new IllegalArgumentException("The input array cannot be null");
26+
}
2427
if (array.length == 0) {
2528
return array;
2629
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
package com.thealgorithms.sorts;
22

3+
import static org.junit.jupiter.api.Assertions.assertThrows;
4+
5+
import org.junit.jupiter.api.Test;
6+
37
public class BitonicSortTest extends SortingAlgorithmTest {
48
@Override
59
SortAlgorithm getSortAlgorithm() {
610
return new BitonicSort();
711
}
12+
13+
@Test
14+
void shouldRejectNullArray() {
15+
assertThrows(IllegalArgumentException.class, () -> getSortAlgorithm().sort((Integer[]) null));
16+
}
817
}

0 commit comments

Comments
 (0)