{"record":{"id":"b7d9abb7a7493c76","repo":"TheAlgorithms/Java","slug":"input-array-cannot-be-null-or-empty","errorCode":null,"errorMessage":"Input array cannot be null or empty.","messagePattern":"Input array cannot be null or empty\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/dynamicprogramming/WineProblem.java","lineNumber":88,"sourceCode":"        int start = wptd(arr, si + 1, ei, strg) + arr[si] * year;\n        int end = wptd(arr, si, ei - 1, strg) + arr[ei] * year;\n\n        int ans = Math.max(start, end);\n        strg[si][ei] = ans;\n\n        return ans;\n    }\n\n    /**\n     * Calculate maximum profit using bottom-up dynamic programming with tabulation.\n     *\n     * @param arr Array of wine prices.\n     * @throws IllegalArgumentException if the input array is null or empty.\n     * @return Maximum profit obtainable by selling the wines.\n     */\n    public static int wpbu(int[] arr) {\n        if (arr == null || arr.length == 0) {\n            throw new IllegalArgumentException(\"Input array cannot be null or empty.\");\n        }\n        int n = arr.length;\n        int[][] strg = new int[n][n];\n\n        for (int slide = 0; slide <= n - 1; slide++) {\n            for (int si = 0; si <= n - slide - 1; si++) {\n                int ei = si + slide;\n                int year = (n - (ei - si + 1)) + 1;\n                if (si == ei) {\n                    strg[si][ei] = arr[si] * year;\n                } else {\n                    int start = strg[si + 1][ei] + arr[si] * year;\n                    int end = strg[si][ei - 1] + arr[ei] * year;\n\n                    strg[si][ei] = Math.max(start, end);\n                }\n            }\n        }","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/dynamicprogramming/WineProblem.java#L70-L106","documentation":"Thrown by WineProblem.wpbu(int[] arr) when arr is null or empty. The bottom-up DP allocates strg = new int[n][n] where n = arr.length; an empty array yields a degenerate 0x0 table and null NPEs on access. Message: 'Input array cannot be null or empty.'","triggerScenarios":"Passing null or an empty price array; loading wine prices from an empty source; uninitialized array field.","commonSituations":"Reading prices from a config/file that was empty; tests with an empty fixture; refactoring that left the array unset.","solutions":["Ensure the array has at least one element before calling wpbu.","Validate arr != null && arr.length > 0 at the boundary.","Default to a sensible non-empty input or report the empty source upstream."],"exampleFix":"// before\nint profit = WineProblem.wpbu(arr);\n\n// after\nif (arr == null || arr.length == 0) throw new IllegalArgumentException(\"prices required\");\nint profit = WineProblem.wpbu(arr);","handlingStrategy":"validation","validationCode":"if (arr == null || arr.length == 0) {\n    throw new IllegalArgumentException(\"wine prices required\");\n}\nWineProblem.wpbu(arr);","typeGuard":"arr != null && arr.length > 0","tryCatchPattern":null,"preventionTips":["Default to a non-empty price array when the source is empty.","Validate at the data-load boundary.","Add a test for the empty-array case."],"tags":["null-check","array","dynamic-programming","input-validation"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}