{"record":{"id":"d32e6332a9469328","repo":"TheAlgorithms/Java","slug":"radius-must-be-greater-than-0","errorCode":null,"errorMessage":"Radius must be greater than 0","messagePattern":"Radius must be greater than 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/Area.java","lineNumber":67,"sourceCode":"        }\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    /**\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        }","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/Area.java#L49-L85","documentation":"Thrown by Area.surfaceAreaSphere when radius <= 0. The message comes from the POSITIVE_RADIUS constant ('Radius must be greater than 0'). The sphere surface area 4*pi*r^2 requires a positive radius, so zero/negative radii are rejected.","triggerScenarios":"surfaceAreaSphere(0); surfaceAreaSphere(-5.0); passing a radius computed from a distance that came out 0.","commonSituations":"Radius derived as a difference of identical points (0); default 0.0 field; negative radius from a signed-distance calculation.","solutions":["Pass radius > 0: surfaceAreaSphere(3.0).","Guard the radius before calling and report a domain error.","Where radius is a distance, reject the degenerate same-point case upstream."],"exampleFix":"// before\ndouble a = Area.surfaceAreaSphere(r);\n// after\nif (r <= 0) throw new IllegalArgumentException(\"radius must be > 0\");\ndouble a = Area.surfaceAreaSphere(r);","handlingStrategy":"validation","validationCode":"if (!(radius > 0)) {\n    throw new IllegalArgumentException(\"sphere radius must be > 0\");\n}\ndouble a = Area.surfaceAreaSphere(radius);","typeGuard":"static boolean isPositiveDimension(double d) {\n    return d > 0 && Double.isFinite(d);\n}","tryCatchPattern":"try {\n    double a = Area.surfaceAreaSphere(r);\n} catch (IllegalArgumentException e) {\n    // radius non-positive; reject input\n}","preventionTips":["Reject the degenerate same-point case when radius is a distance.","Validate radius against NaN/Infinity as well as <= 0.","Centralize all 'positive dimension' checks in one helper."],"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"}