{"record":{"id":"6eb46f4956ecf6c6","repo":"TheAlgorithms/Java","slug":"length-must-be-greater-than-0","errorCode":null,"errorMessage":"Length must be greater than 0","messagePattern":"Length must be greater than 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/Area.java","lineNumber":48,"sourceCode":"     */\n    public static double surfaceAreaCube(final double sideLength) {\n        if (sideLength <= 0) {\n            throw new IllegalArgumentException(\"Side length must be greater than 0\");\n        }\n        return 6 * sideLength * sideLength;\n    }\n\n    /**\n     * Calculate the surface area of a cuboid.\n     *\n     * @param length length of the cuboid\n     * @param width width of the cuboid\n     * @param height height of the cuboid\n     * @return surface area of given cuboid\n     */\n    public static double surfaceAreaCuboid(final double length, double width, double height) {\n        if (length <= 0) {\n            throw new IllegalArgumentException(\"Length must be greater than 0\");\n        }\n        if (width <= 0) {\n            throw new IllegalArgumentException(\"Width must be greater than 0\");\n        }\n        if (height <= 0) {\n            throw new IllegalArgumentException(\"Height must be greater than 0\");\n        }\n        return 2 * (length * width + length * height + width * height);\n    }\n\n    /**\n     * Calculate the surface area of a sphere.\n     *\n     * @param radius radius of sphere\n     * @return surface area of given sphere\n     */\n    public static double surfaceAreaSphere(final double radius) {\n        if (radius <= 0) {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/Area.java#L30-L66","documentation":"Thrown by Area.surfaceAreaCuboid when the 'length' argument is <= 0. This is the first of three sequential guards (length, then width, then height) on the cuboid surface-area formula 2*(l*w + l*h + w*h); a non-positive length is caught before width/height are even checked.","triggerScenarios":"surfaceAreaCuboid(0, 2, 2); surfaceAreaCuboid(-1, 2, 2); any call where the first dimension is non-positive.","commonSituations":"Passing a partially-populated dimensions object where length defaulted to 0; sign error in a conversion producing a negative length.","solutions":["Pass length > 0 as the first argument: surfaceAreaCuboid(2, 3, 4).","Validate all three dimensions up front so the error names the real offender.","Build a small Dimensions value object that rejects non-positive values at construction."],"exampleFix":"// before\ndouble a = Area.surfaceAreaCuboid(l, w, h);\n// after\nif (l <= 0 || w <= 0 || h <= 0) throw new IllegalArgumentException(\"dimensions must be > 0\");\ndouble a = Area.surfaceAreaCuboid(l, w, h);","handlingStrategy":"validation","validationCode":"if (length <= 0 || width <= 0 || height <= 0) {\n    throw new IllegalArgumentException(\"cuboid dimensions must be > 0\");\n}\ndouble a = Area.surfaceAreaCuboid(length, width, height);","typeGuard":"static boolean allPositive(double... dims) {\n    for (double d : dims) if (!(d > 0)) return false;\n    return true;\n}","tryCatchPattern":"try {\n    double a = Area.surfaceAreaCuboid(l, w, h);\n} catch (IllegalArgumentException e) {\n    // one of l/w/h was non-positive; identify which\n}","preventionTips":["Validate all three dimensions before the call for a single clear error.","Keep argument order (length, width, height) consistent across your code.","Use a Dimensions value object that rejects non-positive values at construction."],"tags":["validation","maths","geometry","precondition","illegal-argument"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}