{"record":{"id":"8c89c9e77ee49d94","repo":"elastic/elasticsearch","slug":"invalid-cartesian-rectangle-minx-s-maxx-s","errorCode":null,"errorMessage":"Invalid cartesian rectangle: minX (%s) > maxX (%s)","messagePattern":"Invalid cartesian rectangle: minX \\((.+?)\\) > maxX \\((.+?)\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libs/geo/src/main/java/org/elasticsearch/geometry/utils/SpatialEnvelopeVisitor.java","lineNumber":161,"sourceCode":"            return maxY;\n        }\n\n        public double getMinY() {\n            return minY;\n        }\n\n        @Override\n        public void visitPoint(double x, double y) {\n            minX = Math.min(minX, x);\n            maxX = Math.max(maxX, x);\n            maxY = Math.max(maxY, y);\n            minY = Math.min(minY, y);\n        }\n\n        @Override\n        public void visitRectangle(double minX, double maxX, double maxY, double minY) {\n            if (minX > maxX) {\n                throw new IllegalArgumentException(\n                    String.format(Locale.ROOT, \"Invalid cartesian rectangle: minX (%s) > maxX (%s)\", minX, maxX)\n                );\n            }\n            this.minX = Math.min(this.minX, minX);\n            this.maxX = Math.max(this.maxX, maxX);\n            this.maxY = Math.max(this.maxY, maxY);\n            this.minY = Math.min(this.minY, minY);\n        }\n\n        @Override\n        public boolean isValid() {\n            return minY != Double.POSITIVE_INFINITY;\n        }\n\n        @Override\n        public Rectangle getResult() {\n            return new Rectangle(minX, maxX, maxY, minY);\n        }","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/geo/src/main/java/org/elasticsearch/geometry/utils/SpatialEnvelopeVisitor.java#L143-L179","documentation":"Thrown by SpatialEnvelopeVisitor's visitRectangle override when a cartesian rectangle has minX > maxX. The visitor accumulates an envelope over a geometry; in cartesian space an inverted x-range is invalid (unlike geographic, where minX > maxX can denote an antimeridian-crossing envelope). The message uses String.format with Locale.ROOT and includes both ordinates.","triggerScenarios":"Visiting a Rectangle whose minX exceeds maxX through a SpatialEnvelopeVisitor configured for cartesian mode. The visitor's visitRectangle method explicitly checks before folding the rectangle into the running envelope.","commonSituations":"Geographic data (longitudes that cross the antimeridian) routed through a cartesian envelope visitor; argument-order bugs passing (maxX, minX); inverted rectangles coming from upstream bounding-box computations.","solutions":["If the data is geographic, use the geographic variant of the envelope visitor that tolerates minX > maxX.","For cartesian data, ensure minX <= maxX before visiting — normalize or reject inverted rectangles upstream.","Pass rectangle ordinates in the (minX, maxX, maxY, minY) order expected by visitRectangle."],"exampleFix":"// before\nvisitor.visitRectangle(170, -170, 20, -20); // cartesian, minX > maxX\n\n// after (geographic data)\n// use the geographic envelope visitor that handles antimeridian crossing\n// or, for true cartesian:\nvisitor.visitRectangle(-170, 170, 20, -20);","handlingStrategy":"validation","validationCode":"if (dataIsGeographic) {\n    // use a geographic envelope visitor that tolerates minX > maxX\n} else {\n    if (minX > maxX) throw new IllegalArgumentException(\"cartesian rectangle minX > maxX\");\n    visitor.visitRectangle(minX, maxX, maxY, minY);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Choose the envelope visitor by CRS — geographic tolerates antimeridian crossing, cartesian does not.","Pass rectangle ordinates in (minX, maxX, maxY, minY) order.","Normalize or reject inverted cartesian rectangles upstream."],"tags":["geometry","envelope","cartesian","bounding-box","visitor","libs-geo"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}