{"record":{"id":"ee837544dba6d8b0","repo":"TheAlgorithms/Java","slug":"base-must-be-greater-than-02","errorCode":null,"errorMessage":"Base must be greater than 02","messagePattern":"Base must be greater than 02","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/Area.java","lineNumber":185,"sourceCode":"            throw new IllegalArgumentException(POSITIVE_HEIGHT);\n        }\n        return baseLength * height;\n    }\n\n    /**\n     * Calculate the area of a trapezium.\n     *\n     * @param base1  upper base of trapezium\n     * @param base2  bottom base of trapezium\n     * @param height height of trapezium\n     * @return area of given trapezium\n     */\n    public static double surfaceAreaTrapezium(final double baseLength1, final double baseLength2, final double height) {\n        if (baseLength1 <= 0) {\n            throw new IllegalArgumentException(POSITIVE_BASE + 1);\n        }\n        if (baseLength2 <= 0) {\n            throw new IllegalArgumentException(POSITIVE_BASE + 2);\n        }\n        if (height <= 0) {\n            throw new IllegalArgumentException(POSITIVE_HEIGHT);\n        }\n        return (baseLength1 + baseLength2) * height / 2;\n    }\n\n    /**\n     * Calculate the area of a circle.\n     *\n     * @param radius radius of circle\n     * @return area of given circle\n     */\n    public static double surfaceAreaCircle(final double radius) {\n        if (radius <= 0) {\n            throw new IllegalArgumentException(POSITIVE_RADIUS);\n        }\n        return Math.PI * radius * radius;","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/Area.java#L167-L203","documentation":"Thrown by surfaceAreaTrapezium when the second base parameter (baseLength2) is zero or negative. The message 'Base must be greater than 02' results from POSITIVE_BASE + 2 — the string constant concatenated with integer literal 2, producing the misleading suffix '02'. The check fires only after baseLength1 passes its own validation.","triggerScenarios":"Calling Area.surfaceAreaTrapezium(baseLength1, baseLength2, height) where baseLength1 > 0 but baseLength2 <= 0. For example, surfaceAreaTrapezium(5, 0, 3) or surfaceAreaTrapezium(5, -2, 3).","commonSituations":"Asymmetric data entry where one base dimension is correctly populated but the other defaults to 0. Common when reading two separate fields from a database or DTO and one column is nullable/zero-default. Copy-paste of dimensions where the second value was forgotten.","solutions":["Validate baseLength2 > 0 independently before calling surfaceAreaTrapezium.","Audit the data source for the second base field — check for null-to-zero coercion, missing columns, or swapped argument order.","Fix the library message: replace POSITIVE_BASE + 2 with a clear message like POSITIVE_BASE + ' for base 2' to avoid the '02' artifact."],"exampleFix":"// before\nArea.surfaceAreaTrapezium(5, 0, 3); // throws 'Base must be greater than 02'\n\n// after (validate all inputs upfront)\nif (baseLength1 <= 0 || baseLength2 <= 0 || height <= 0) {\n    throw new IllegalArgumentException(\"All trapezium dimensions must be positive\");\n}\ndouble area = Area.surfaceAreaTrapezium(baseLength1, baseLength2, height);","handlingStrategy":"validation","validationCode":"// Validate trapezium baseLength2 before calling surfaceAreaTrapezium\nif (baseLength2 <= 0) {\n    throw new IllegalArgumentException(\"Trapezium base2 must be positive, got: \" + baseLength2);\n}\ndouble area = Area.surfaceAreaTrapezium(baseLength1, baseLength2, height);","typeGuard":"static boolean isValidDimension(double value) {\n    return value > 0 && !Double.isNaN(value) && Double.isFinite(value);\n}","tryCatchPattern":null,"preventionTips":["Validate all parameters in a single guard block before calling surfaceAreaTrapezium.","Ensure both base dimensions are populated from the data source — check for asymmetric null/zero defaults.","If pattern-matching error messages, note POSITIVE_BASE + 2 produces '02' not '0'."],"tags":["geometry","input-validation","area","java","string-concatenation-bug"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}