{"record":{"id":"e11a6210e74ead42","repo":"elastic/elasticsearch","slug":"max-y-cannot-be-less-than-min-y","errorCode":null,"errorMessage":"max y cannot be less than min y","messagePattern":"max y cannot be less than min y","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libs/geo/src/main/java/org/elasticsearch/geometry/Rectangle.java","lineNumber":75,"sourceCode":"     * Constructs a bounding box by first validating the provided latitude and longitude coordinates\n     */\n    public Rectangle(double minX, double maxX, double maxY, double minY) {\n        this(minX, maxX, maxY, minY, Double.NaN, Double.NaN);\n    }\n\n    /**\n     * Constructs a bounding box by first validating the provided latitude and longitude coordinates\n     */\n    public Rectangle(double minX, double maxX, double maxY, double minY, double minZ, double maxZ) {\n        this.minX = minX;\n        this.maxX = maxX;\n        this.minY = minY;\n        this.maxY = maxY;\n        this.minZ = minZ;\n        this.maxZ = maxZ;\n        empty = false;\n        if (maxY < minY) {\n            throw new IllegalArgumentException(\"max y cannot be less than min y\");\n        }\n        if (Double.isNaN(minZ) != Double.isNaN(maxZ)) {\n            throw new IllegalArgumentException(\"only one z value is specified\");\n        }\n    }\n\n    public double getMinY() {\n        return minY;\n    }\n\n    public double getMinX() {\n        return minX;\n    }\n\n    public double getMinZ() {\n        return minZ;\n    }\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/geo/src/main/java/org/elasticsearch/geometry/Rectangle.java#L57-L93","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nnew Rectangle(0, 10, -20, 20, Double.NaN, Double.NaN); // maxY(-20) < minY(20)\n\n// after\nnew Rectangle(0, 10, 20, -20, Double.NaN, Double.NaN); // maxY(20) >= minY(-20)","handlingStrategy":"validation","validationCode":"double minY = Math.min(y1, y2);\ndouble maxY = Math.max(y1, y2);\nif (maxY < minY) throw new IllegalArgumentException(\"y bounds inverted after normalize (unexpected)\");\nnew Rectangle(minX, maxX, maxY, minY, minZ, maxZ);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["geometry","rectangle","validation","argument-order","libs-geo"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}