TheAlgorithms/Java · error · IllegalArgumentException

Base must be greater than 01

Error message

Base must be greater than 01

What it means

Thrown by surfaceAreaTrapezium when the first base parameter (baseLength1) is zero or negative. The message 'Base must be greater than 01' is the result of the string constant POSITIVE_BASE ('Base must be greater than 0') being concatenated with the integer literal 1 (POSITIVE_BASE + 1), a Java string concatenation that appends '1' to the text. The intent is to distinguish this base from baseLength2, but the resulting message reads as a typo ('01').

Source

Thrown at src/main/java/com/thealgorithms/maths/Area.java:182

            throw new IllegalArgumentException(POSITIVE_BASE);
        }
        if (height <= 0) {
            throw new IllegalArgumentException(POSITIVE_HEIGHT);
        }
        return baseLength * height;
    }

    /**
     * Calculate the area of a trapezium.
     *
     * @param base1  upper base of trapezium
     * @param base2  bottom base of trapezium
     * @param height height of trapezium
     * @return area of given trapezium
     */
    public static double surfaceAreaTrapezium(final double baseLength1, final double baseLength2, final double height) {
        if (baseLength1 <= 0) {
            throw new IllegalArgumentException(POSITIVE_BASE + 1);
        }
        if (baseLength2 <= 0) {
            throw new IllegalArgumentException(POSITIVE_BASE + 2);
        }
        if (height <= 0) {
            throw new IllegalArgumentException(POSITIVE_HEIGHT);
        }
        return (baseLength1 + baseLength2) * height / 2;
    }

    /**
     * Calculate the area of a circle.
     *
     * @param radius radius of circle
     * @return area of given circle
     */
    public static double surfaceAreaCircle(final double radius) {
        if (radius <= 0) {

View on GitHub (pinned to fdfb9a395b)

Solutions

  1. Ensure baseLength1 is a strictly positive value before calling surfaceAreaTrapezium (e.g., add a guard: if (baseLength1 <= 0) throw or clamp).
  2. Check upstream data parsing — verify the source value is not blank, null-string, or negative before conversion to double.
  3. If you control the library, fix the message bug: POSITIVE_BASE + 1 should be POSITIVE_BASE + ' 1' or a distinct constant to avoid the misleading '01' suffix.

Example fix

// before
Area.surfaceAreaTrapezium(0, 5, 3); // throws 'Base must be greater than 01'

// after (caller validates)
if (baseLength1 > 0 && baseLength2 > 0 && height > 0) {
    Area.surfaceAreaTrapezium(baseLength1, baseLength2, height);
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate trapezium baseLength1 before calling surfaceAreaTrapezium
if (baseLength1 <= 0) {
    throw new IllegalArgumentException("Trapezium base1 must be positive, got: " + baseLength1);
}
double area = Area.surfaceAreaTrapezium(baseLength1, baseLength2, height);

Type guard

// For double dimensions, a simple predicate suffices
static boolean isValidDimension(double value) {
    return value > 0 && !Double.isNaN(value) && Double.isFinite(value);
}

Prevention

When it happens

Trigger: Calling Area.surfaceAreaTrapezium(baseLength1, baseLength2, height) where baseLength1 <= 0 (e.g., 0, -3.5, -0.001). Only the first base argument triggers this specific message; the second base triggers error 361.

Common situations: Parsing user-provided dimensions from a form or config file where the field was left blank (parsed as 0) or a negative sign was accidentally included. Unit conversion errors (e.g., passing millimeters as 0 after rounding) or defaulting an uninitialized double field (0.0) can also produce this.

Related errors


AI-assisted analysis of TheAlgorithms/Java@fdfb9a395b (2026-08-13). Data as JSON: /api/errors/4ee5caff7b2a2cc4. Report an issue: GitHub.