{"record":{"id":"3508b2418f9a9ad9","repo":"TheAlgorithms/Java","slug":"side-length-must-be-greater-than-0","errorCode":null,"errorMessage":"Side length must be greater than 0","messagePattern":"Side length must be greater than 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/Area.java","lineNumber":33,"sourceCode":"    /**\n     * String of IllegalArgumentException for height\n     */\n    private static final String POSITIVE_HEIGHT = \"Height must be greater than 0\";\n\n    /**\n     * String of IllegalArgumentException for base\n     */\n    private static final String POSITIVE_BASE = \"Base must be greater than 0\";\n\n    /**\n     * Calculate the surface area of a cube.\n     *\n     * @param sideLength side length of cube\n     * @return surface area of given cube\n     */\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\");","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/Area.java#L15-L51","documentation":"Thrown by Area.surfaceAreaCube when sideLength <= 0. A cube must have a positive side length for the 6*s^2 formula to represent a real geometric surface area; zero or negative lengths are physically meaningless and rejected at entry.","triggerScenarios":"surfaceAreaCube(0); surfaceAreaCube(-2.0); passing an uninitialized/zeroed measurement field.","commonSituations":"Default double field of 0.0 used before measurement assignment; user form left blank parsing to 0; unit conversion error producing a tiny/negative value.","solutions":["Pass a positive side length: surfaceAreaCube(3.0).","Validate the dimension before calling and surface a domain error to the user.","Ensure measurement inputs are loaded/defaulted to a positive value, not 0."],"exampleFix":"// before\ndouble a = Area.surfaceAreaCube(side);\n// after\nif (side <= 0) throw new IllegalArgumentException(\"side must be > 0\");\ndouble a = Area.surfaceAreaCube(side);","handlingStrategy":"validation","validationCode":"if (!(sideLength > 0)) {\n    throw new IllegalArgumentException(\"cube side length must be > 0\");\n}\ndouble a = Area.surfaceAreaCube(sideLength);","typeGuard":"static boolean isPositiveDimension(double d) {\n    return d > 0 && !Double.isNaN(d) && Double.isFinite(d);\n}","tryCatchPattern":"try {\n    double a = Area.surfaceAreaCube(side);\n} catch (IllegalArgumentException e) {\n    // non-positive side; prompt user for valid measurement\n}","preventionTips":["Default measurement fields to a sentinel and validate, not to 0.0.","Check for NaN/Infinity too, since doubles can carry them.","Centralize dimension validation in one helper for all Area calls."],"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"}