{"record":{"id":"08151a3c155b7179","repo":"TheAlgorithms/Java","slug":"height-must-be-greater-than-0","errorCode":null,"errorMessage":"Height must be greater than 0","messagePattern":"Height must be greater than 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/Area.java","lineNumber":54,"sourceCode":"    }\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) {\n            throw new IllegalArgumentException(POSITIVE_RADIUS);\n        }\n        return 4 * Math.PI * radius * radius;\n    }\n\n    /**","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/Area.java#L36-L72","documentation":"Thrown by Area.surfaceAreaCuboid when the 'height' argument is <= 0. This is the final guard in the cuboid method; reaching it means length and width were both valid, so the failure is specifically the height.","triggerScenarios":"surfaceAreaCuboid(2, 3, 0); surfaceAreaCuboid(2, 3, -1); valid length and width with a non-positive height.","commonSituations":"2D-first code paths that default the third dimension to 0; height derived from a subtraction that went negative.","solutions":["Pass height > 0 as the third argument: surfaceAreaCuboid(2, 3, 4).","Pre-validate all dimensions together to report the true offending field.","Ensure the height source is always populated for 3D calls."],"exampleFix":"// before\ndouble a = Area.surfaceAreaCuboid(l, w, h);\n// after\nif (h <= 0) throw new IllegalArgumentException(\"height must be > 0\");\ndouble a = Area.surfaceAreaCuboid(l, w, h);","handlingStrategy":"validation","validationCode":"if (height <= 0) {\n    throw new IllegalArgumentException(\"cuboid height must be > 0\");\n}\ndouble a = Area.surfaceAreaCuboid(length, width, height);","typeGuard":"static boolean isPositiveDimension(double d) {\n    return d > 0 && Double.isFinite(d);\n}","tryCatchPattern":"try {\n    double a = Area.surfaceAreaCuboid(l, w, h);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Height\")) { /* height offender */ }\n}","preventionTips":["Ensure 3D calls always populate height (2D-first code often leaves it 0).","Pre-validate all three dimensions for one consolidated error.","Guard against height derived from subtraction going negative."],"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"}