{"record":{"id":"3b37005c61b198a6","repo":"TheAlgorithms/Java","slug":"array-must-be-non-empty-3b3700","errorCode":null,"errorMessage":"array must be non-empty.","messagePattern":"array must be non-empty\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/FindMinRecursion.java","lineNumber":19,"sourceCode":"package com.thealgorithms.maths;\n\npublic final class FindMinRecursion {\n\n    private FindMinRecursion() {\n    }\n\n    /**\n     * Get min of an array using divide and conquer algorithm\n     *\n     * @param array contains elements\n     * @param low the index of the first element\n     * @param high the index of the last element\n     * @return min of {@code array}\n     */\n\n    public static int min(final int[] array, final int low, final int high) {\n        if (array.length == 0) {\n            throw new IllegalArgumentException(\"array must be non-empty.\");\n        }\n        if (low == high) {\n            return array[low]; // or array[high]\n        }\n\n        int mid = (low + high) >>> 1;\n\n        int leftMin = min(array, low, mid); // get min in [low, mid]\n        int rightMin = min(array, mid + 1, high); // get min in [mid+1, high]\n\n        return Math.min(leftMin, rightMin);\n    }\n\n    /**\n     * Get min of an array using recursion algorithm\n     *\n     * @param array contains elements\n     * @return min value of {@code array}","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/FindMinRecursion.java#L1-L37","documentation":"Thrown by FindMinRecursion.min(int[] array, int low, int high) when array.length is 0. This is the recursive divide-and-conquer counterpart to FindMinRecursion, splitting [low, high] recursively and returning array[low] when low == high. An empty array yields no valid minimum. Note the message uses lowercase 'array' unlike FindMax's 'Array', so string-matching on the exact case matters if catching by message.","triggerScenarios":"Calling min(new int[0], 0, 0) or min(emptyArray, anyLow, anyHigh). The length check fires before any index validation, so empty-array callers always hit this message rather than an IndexOutOfBounds.","commonSituations":"Empty arrays from filtered or partitioned data. Recursive code paths that receive shrunk sub-arrays. Test fixtures missing initialization.","solutions":["Ensure array.length > 0 before calling min().","Validate low and high are within [0, array.length - 1] and low <= high.","Add a wrapper that rejects empty or out-of-bounds inputs before delegating."],"exampleFix":"// before\nint result = FindMinRecursion.min(arr, 0, arr.length - 1);\n\n// after\nif (arr.length == 0) {\n    throw new IllegalArgumentException(\"Cannot compute min of empty array\");\n}\nif (low < 0 || high >= arr.length || low > high) {\n    throw new IndexOutOfBoundsException(\"Invalid range [\" + low + \", \" + high + \"]\");\n}\nint result = FindMinRecursion.min(arr, low, high);","handlingStrategy":"validation","validationCode":"if (array == null || array.length == 0) {\n    throw new IllegalArgumentException(\"Array must be non-empty\");\n}\nif (low < 0 || high >= array.length || low > high) {\n    throw new IndexOutOfBoundsException(\"Invalid range [\" + low + \", \" + high + \"]\");\n}\nint result = FindMinRecursion.min(array, low, high);","typeGuard":"static boolean isValidRange(int[] array, int low, int high) {\n    return array != null && array.length > 0\n        && low >= 0 && high < array.length && low <= high;\n}","tryCatchPattern":"try {\n    int result = FindMinRecursion.min(array, low, high);\n} catch (IllegalArgumentException e) {\n    // empty array; handle gracefully\n}","preventionTips":["Validate array non-emptiness AND index bounds before calling.","Note the lowercase 'array' in the error message if matching by string.","Ensure low <= high and both are within [0, length-1]."],"tags":["math","array","recursion","divide-and-conquer","empty-collection","argument-validation"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}