elastic/elasticsearch · error · IllegalArgumentException
max y cannot be less than min y
Error message
max y cannot be less than min y
What it means
Thrown by the 6-argument Rectangle constructor (minX, maxX, maxY, minY, minZ, maxZ) when maxY is less than minY. The Rectangle class represents a bounding box whose vertical extents must be correctly ordered. Note the constructor assigns the fields BEFORE validating, so the partially-built object exists momentarily but the exception still propagates and prevents the caller from receiving a reference.
Source
Thrown at libs/geo/src/main/java/org/elasticsearch/geometry/Rectangle.java:75
* Constructs a bounding box by first validating the provided latitude and longitude coordinates
*/
public Rectangle(double minX, double maxX, double maxY, double minY) {
this(minX, maxX, maxY, minY, Double.NaN, Double.NaN);
}
/**
* Constructs a bounding box by first validating the provided latitude and longitude coordinates
*/
public Rectangle(double minX, double maxX, double maxY, double minY, double minZ, double maxZ) {
this.minX = minX;
this.maxX = maxX;
this.minY = minY;
this.maxY = maxY;
this.minZ = minZ;
this.maxZ = maxZ;
empty = false;
if (maxY < minY) {
throw new IllegalArgumentException("max y cannot be less than min y");
}
if (Double.isNaN(minZ) != Double.isNaN(maxZ)) {
throw new IllegalArgumentException("only one z value is specified");
}
}
public double getMinY() {
return minY;
}
public double getMinX() {
return minX;
}
public double getMinZ() {
return minZ;
}
View on GitHub (pinned to db6a809a66)
Solutions
- Reorder the arguments so maxY is the larger latitude value: the signature is (minX, maxX, maxY, minY, minZ, maxZ).
- If you cannot trust input ordering, normalize before constructing: `double lo = Math.min(a, b); double hi = Math.max(a, b); new Rectangle(minX, maxX, hi, lo, minZ, maxZ);`
- If you genuinely need an inverted envelope (e.g. antimeridian crossing in y), Rectangle cannot represent it — use a different geometry or restructure the query.
Example fix
// before new Rectangle(0, 10, -20, 20, Double.NaN, Double.NaN); // maxY(-20) < minY(20) // after new Rectangle(0, 10, 20, -20, Double.NaN, Double.NaN); // maxY(20) >= minY(-20)
Defensive patterns
Strategy: validation
Validate before calling
double minY = Math.min(y1, y2);
double maxY = Math.max(y1, y2);
if (maxY < minY) throw new IllegalArgumentException("y bounds inverted after normalize (unexpected)");
new Rectangle(minX, maxX, maxY, minY, minZ, maxZ); Prevention
- Memorize the 6-arg Rectangle signature order: (minX, maxX, maxY, minY, minZ, maxZ) — maxY comes before minY.
- Always normalize min/max pairs with Math.min/Math.max before constructing a Rectangle.
- Wrap Rectangle construction in a single helper that accepts unordered bounds and orders them internally.
When it happens
Trigger: Calling `new Rectangle(minX, maxX, maxY, minY, minZ, maxZ)` where the third argument (maxY) is numerically smaller than the fourth argument (minY). The argument order (maxY before minY) is the most common culprit — callers passing values in min-then-max order will trip this check.
Common situations: Passing bounds in (minY, maxY) order to a constructor whose signature is (maxY, minY); deserializing user-supplied or external data whose y-ordinates are inverted; computing bounding boxes from point clouds where a comparison helper flipped its min/max arguments.
Related errors
- only one z value is specified
- max x cannot be less than min x
- invalid latitude
- invalid longitude
- found Z value [
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/e11a6210e74ead42.
Report an issue: GitHub.