TheAlgorithms/Java · error · IllegalArgumentException
Base must be greater than 02
Error message
Base must be greater than 02
What it means
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.
Source
Thrown at src/main/java/com/thealgorithms/maths/Area.java:185
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) {
throw new IllegalArgumentException(POSITIVE_RADIUS);
}
return Math.PI * radius * radius;View on GitHub (pinned to fdfb9a395b)
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.
Example fix
// before
Area.surfaceAreaTrapezium(5, 0, 3); // throws 'Base must be greater than 02'
// after (validate all inputs upfront)
if (baseLength1 <= 0 || baseLength2 <= 0 || height <= 0) {
throw new IllegalArgumentException("All trapezium dimensions must be positive");
}
double area = Area.surfaceAreaTrapezium(baseLength1, baseLength2, height); Defensive patterns
Strategy: validation
Validate before calling
// Validate trapezium baseLength2 before calling surfaceAreaTrapezium
if (baseLength2 <= 0) {
throw new IllegalArgumentException("Trapezium base2 must be positive, got: " + baseLength2);
}
double area = Area.surfaceAreaTrapezium(baseLength1, baseLength2, height); Type guard
static boolean isValidDimension(double value) {
return value > 0 && !Double.isNaN(value) && Double.isFinite(value);
} Prevention
- 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'.
When it happens
Trigger: Calling Area.surfaceAreaTrapezium(baseLength1, baseLength2, height) where baseLength1 > 0 but baseLength2 <= 0. For example, surfaceAreaTrapezium(5, 0, 3) or surfaceAreaTrapezium(5, -2, 3).
Common situations: 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.
Related errors
- Base must be greater than 01
- Invalid unit '{}'. Supported units are: {}
- inputUnit must be different from outputUnit.
- NULL_INPUT
- UNKNOWN_WORD
AI-assisted analysis of TheAlgorithms/Java@fdfb9a395b (2026-08-13).
Data as JSON: /api/errors/ee837544dba6d8b0.
Report an issue: GitHub.