{"record":{"id":"1b6b472df214a9d8","repo":"TheAlgorithms/Java","slug":"width-must-be-greater-than-0","errorCode":null,"errorMessage":"Width must be greater than 0","messagePattern":"Width must be greater than 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/Area.java","lineNumber":51,"sourceCode":"            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) {\n            throw new IllegalArgumentException(POSITIVE_RADIUS);\n        }\n        return 4 * Math.PI * radius * radius;","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/Area.java#L33-L69","documentation":"Thrown by Area.surfaceAreaCuboid when the 'width' argument is <= 0. It fires only after length passes its guard (length > 0) but before height is checked, so it specifically indicates a non-positive width with a valid length.","triggerScenarios":"surfaceAreaCuboid(2, 0, 2); surfaceAreaCuboid(2, -3, 4); a valid length paired with a zero/negative width.","commonSituations":"Dimensions loaded from different sources where width came in as 0 or negative; column-vs-row index mix-up producing a 0 width.","solutions":["Pass width > 0 as the second argument: surfaceAreaCuboid(2, 3, 4).","Validate the full dimension set before the call to get one consolidated error.","Confirm the argument order matches the signature (length, width, height)."],"exampleFix":"// before\ndouble a = Area.surfaceAreaCuboid(l, w, h);\n// after\nif (w <= 0) throw new IllegalArgumentException(\"width must be > 0\");\ndouble a = Area.surfaceAreaCuboid(l, w, h);","handlingStrategy":"validation","validationCode":"if (width <= 0) {\n    throw new IllegalArgumentException(\"cuboid width 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(\"Width\")) { /* width offender */ }\n}","preventionTips":["Confirm argument order: width is the second parameter.","Pre-validate the full set so the right field is named.","Centralize dimension validation to avoid per-method duplication."],"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"}