{"record":{"id":"034a76aac91db6da","repo":"TheAlgorithms/Java","slug":"slant-height-must-be-greater-than-0","errorCode":null,"errorMessage":"slant height must be greater than 0","messagePattern":"slant height must be greater than 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/Area.java","lineNumber":84,"sourceCode":"        if (radius <= 0) {\n            throw new IllegalArgumentException(POSITIVE_RADIUS);\n        }\n        return 4 * Math.PI * radius * radius;\n    }\n\n    /**\n     * Calculate the surface area of a pyramid with a square base.\n     *\n     * @param sideLength side length of the square base\n     * @param slantHeight slant height of the pyramid\n     * @return surface area of the given pyramid\n     */\n    public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) {\n        if (sideLength <= 0) {\n            throw new IllegalArgumentException(\"\");\n        }\n        if (slantHeight <= 0) {\n            throw new IllegalArgumentException(\"slant height must be greater than 0\");\n        }\n        double baseArea = sideLength * sideLength;\n        double lateralSurfaceArea = 2 * sideLength * slantHeight;\n        return baseArea + lateralSurfaceArea;\n    }\n\n    /**\n     * Calculate the area of a rectangle.\n     *\n     * @param length length of a rectangle\n     * @param width  width of a rectangle\n     * @return area of given rectangle\n     */\n    public static double surfaceAreaRectangle(final double length, final double width) {\n        if (length <= 0) {\n            throw new IllegalArgumentException(\"Length must be greater than 0\");\n        }\n        if (width <= 0) {","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/Area.java#L66-L102","documentation":"Thrown by Area.surfaceAreaPyramid when slantHeight <= 0, after sideLength has already passed its guard. The message 'slant height must be greater than 0' correctly identifies the field (note the lowercase 'slant', inconsistent with the Title-Case style used elsewhere in the class).","triggerScenarios":"surfaceAreaPyramid(4, 0); surfaceAreaPyramid(4, -3); a valid side paired with a zero/negative slant height.","commonSituations":"Slant height computed from vertical height and side that produced 0/negative via a sqrt or subtraction; default 0.0 field.","solutions":["Pass slantHeight > 0: surfaceAreaPyramid(4, 6).","Validate both pyramid arguments before the call.","Recompute slant height correctly (slant = sqrt((side/2)^2 + height^2)) rather than forwarding a 0."],"exampleFix":"// before\ndouble a = Area.surfaceAreaPyramid(side, slant);\n// after\nif (slant <= 0) throw new IllegalArgumentException(\"slant height must be > 0\");\ndouble a = Area.surfaceAreaPyramid(side, slant);","handlingStrategy":"validation","validationCode":"if (!(slantHeight > 0)) {\n    throw new IllegalArgumentException(\"pyramid slant height must be > 0\");\n}\ndouble a = Area.surfaceAreaPyramid(sideLength, slantHeight);","typeGuard":"static boolean isPositiveDimension(double d) {\n    return d > 0 && Double.isFinite(d);\n}","tryCatchPattern":"try {\n    double a = Area.surfaceAreaPyramid(side, slant);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().toLowerCase().contains(\"slant\")) { /* slant offender */ }\n}","preventionTips":["Compute slant height correctly from side and vertical height rather than passing 0.","Validate both pyramid arguments before the call.","Note the lowercase 'slant' in the message if you match on text."],"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"}