{"record":{"id":"bc9d139aee28a8f3","repo":"TheAlgorithms/Java","slug":"side-length-must-be-greater-than-0-bc9d13","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":133,"sourceCode":"    public static double surfaceAreaCylinder(final double radius, final double height) {\n        if (radius <= 0) {\n            throw new IllegalArgumentException(POSITIVE_RADIUS);\n        }\n        if (height <= 0) {\n            throw new IllegalArgumentException(POSITIVE_HEIGHT);\n        }\n        return 2 * (Math.PI * radius * radius + Math.PI * radius * height);\n    }\n\n    /**\n     * Calculate the area of a square.\n     *\n     * @param sideLength side length of square\n     * @return area of given square\n     */\n    public static double surfaceAreaSquare(final double sideLength) {\n        if (sideLength <= 0) {\n            throw new IllegalArgumentException(\"Side Length must be greater than 0\");\n        }\n        return sideLength * sideLength;\n    }\n\n    /**\n     * Calculate the area of a triangle.\n     *\n     * @param base   base of triangle\n     * @param height height of triangle\n     * @return area of given triangle\n     */\n    public static double surfaceAreaTriangle(final double baseLength, final double height) {\n        if (baseLength <= 0) {\n            throw new IllegalArgumentException(POSITIVE_BASE);\n        }\n        if (height <= 0) {\n            throw new IllegalArgumentException(POSITIVE_HEIGHT);\n        }","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/Area.java#L115-L151","documentation":"Thrown by Area.surfaceAreaSquare when sideLength <= 0. Note the message capitalization differs from the cube guard: 'Side Length must be greater than 0' (two words, Title Case) vs the cube's 'Side length must be greater than 0'. Tests matching on exact text must account for this.","triggerScenarios":"surfaceAreaSquare(0); surfaceAreaSquare(-4); side defaulted to 0.","commonSituations":"Default 0.0 side field; negative value from conversion; tests that assume the same message string as the cube method.","solutions":["Pass sideLength > 0: surfaceAreaSquare(5).","Validate before calling and report a domain error.","If asserting on the message, use the exact 'Side Length' wording or match on type only."],"exampleFix":"// before\ndouble a = Area.surfaceAreaSquare(side);\n// after\nif (side <= 0) throw new IllegalArgumentException(\"side length must be > 0\");\ndouble a = Area.surfaceAreaSquare(side);","handlingStrategy":"validation","validationCode":"if (!(sideLength > 0)) {\n    throw new IllegalArgumentException(\"square side length must be > 0\");\n}\ndouble a = Area.surfaceAreaSquare(sideLength);","typeGuard":"static boolean isPositiveDimension(double d) {\n    return d > 0 && Double.isFinite(d);\n}","tryCatchPattern":"try {\n    double a = Area.surfaceAreaSquare(side);\n} catch (IllegalArgumentException e) {\n    // side non-positive; reject input\n}","preventionTips":["If asserting on message text, use the exact 'Side Length' (Title Case) wording — it differs from the cube's 'Side length'.","Pre-validate side before the call.","Centralize dimension validation."],"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"}