{"record":{"id":"753c180590b8a327","repo":"TheAlgorithms/Java","slug":"the-input-array-cannot-be-null","errorCode":null,"errorMessage":"The input array cannot be null","messagePattern":"The input array cannot be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/sorts/BitonicSort.java","lineNumber":25,"sourceCode":" * BitonicSort class implements the SortAlgorithm interface using the bitonic sort technique.\n */\npublic class BitonicSort implements SortAlgorithm {\n    private enum Direction {\n        DESCENDING,\n        ASCENDING,\n    }\n\n    /**\n     * Sorts the given array using the Bitonic Sort algorithm.\n     *\n     * @param <T> the type of elements in the array, which must implement the Comparable interface\n     * @param array the array to be sorted\n     * @return the sorted array\n     */\n    @Override\n    public <T extends Comparable<T>> T[] sort(T[] array) {\n        if (array == null) {\n            throw new IllegalArgumentException(\"The input array cannot be null\");\n        }\n        if (array.length == 0) {\n            return array;\n        }\n\n        final int paddedSize = nextPowerOfTwo(array.length);\n        T[] paddedArray = Arrays.copyOf(array, paddedSize);\n\n        // Fill the padded part with a maximum value\n        final T maxValue = max(array);\n        Arrays.fill(paddedArray, array.length, paddedSize, maxValue);\n\n        bitonicSort(paddedArray, 0, paddedSize, Direction.ASCENDING);\n        return Arrays.copyOf(paddedArray, array.length);\n    }\n\n    private <T extends Comparable<T>> void bitonicSort(final T[] array, final int low, final int cnt, final Direction direction) {\n        if (cnt > 1) {","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/sorts/BitonicSort.java#L7-L43","documentation":"Thrown by BitonicSort.sort(T[]) when array == null. Bitonic sort pads the array to the next power of two and then compares elements, both of which dereference the array reference. The guard converts a latent NullPointerException into a descriptive IllegalArgumentException before any processing.","triggerScenarios":"Calling sort(null); passing a reference initialized to null; forwarding a value from a Map.get() that returned null.","commonSituations":"Uninitialized fields; data loaders returning null on missing input; null used as a sentinel for 'no data'.","solutions":["Null-check the array before calling sort() and return an empty array or skip.","Initialize collections/arrays to empty rather than null.","Annotate the parameter @NonNull and enable static analysis."],"exampleFix":"// before\nT[] sorted = new BitonicSort().sort(arr);\n\n// after\nif (arr == null) throw new IllegalArgumentException(\"arr must not be null\");\nT[] sorted = new BitonicSort().sort(arr);","handlingStrategy":"validation","validationCode":"if (array == null) throw new IllegalArgumentException(\"array must not be null\");","typeGuard":"public static <T> boolean isSortable(T[] array) { return array != null; }","tryCatchPattern":null,"preventionTips":["Initialize array fields to empty arrays rather than null.","Null-check at the API boundary before sorting.","Annotate with @NonNull and enable static null analysis."],"tags":["sorting","nullable","null-check","input-validation"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}