{"record":{"id":"194896cc66535293","repo":"elastic/elasticsearch","slug":"invalid-longitude","errorCode":null,"errorMessage":"invalid longitude ","messagePattern":"invalid longitude ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libs/geo/src/main/java/org/elasticsearch/geometry/utils/GeographyValidator.java","lineNumber":82,"sourceCode":"    }\n\n    /**\n     * validates latitude value is within standard +/-90 coordinate bounds\n     */\n    protected void checkLatitude(double latitude) {\n        if (Double.isNaN(latitude) || latitude < MIN_LAT_INCL || latitude > MAX_LAT_INCL) {\n            throw new IllegalArgumentException(\n                \"invalid latitude \" + latitude + \"; must be between \" + MIN_LAT_INCL + \" and \" + MAX_LAT_INCL\n            );\n        }\n    }\n\n    /**\n     * validates longitude value is within standard +/-180 coordinate bounds\n     */\n    protected void checkLongitude(double longitude) {\n        if (Double.isNaN(longitude) || longitude < MIN_LON_INCL || longitude > MAX_LON_INCL) {\n            throw new IllegalArgumentException(\n                \"invalid longitude \" + longitude + \"; must be between \" + MIN_LON_INCL + \" and \" + MAX_LON_INCL\n            );\n        }\n    }\n\n    protected void checkAltitude(double zValue) {\n        if (ignoreZValue == false && Double.isNaN(zValue) == false) {\n            throw new IllegalArgumentException(\"found Z value [\" + zValue + \"] but [ignore_z_value] parameter is [\" + ignoreZValue + \"]\");\n        }\n    }\n\n    @Override\n    public void validateCoordinate(double x, double y, double z) {\n        checkLongitude(x);\n        checkLatitude(y);\n        checkAltitude(z);\n    }\n","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/geo/src/main/java/org/elasticsearch/geometry/utils/GeographyValidator.java#L64-L100","documentation":"Thrown by GeographyValidator.checkLongitude when a longitude value is NaN or falls outside the inclusive range [-180.0, 180.0]. Note that longitudes outside [-180, 180] are NOT auto-wrapped here; the validator rejects them. (Antimeridian crossing is handled by allowing minX > maxX in the bbox, not by accepting out-of-range longitudes.)","triggerScenarios":"Any path that calls checkLongitude directly or indirectly (validateCoordinate, validate(Geometry), etc.) with an x-value that is NaN, less than -180.0, or greater than 180.0.","commonSituations":"Raw longitudes in [0, 360) range (some data sources use this instead of [-180, 180)); computations that sum/subtract longitudes without wrapping; swapped lat/lon where a latitude is sent as longitude (this rarely fails since lat is in [-90, 90]); NaN from missing fields.","solutions":["Normalize longitudes to [-180, 180] before validating: `lon = ((lon + 540) % 360) - 180;`","Confirm the field ordering is (lon, lat) for validateCoordinate — GeographyValidator.validateCoordinate treats x as longitude, y as latitude.","Filter NaN if missing data should be skipped."],"exampleFix":"// before\nGeographyValidator.instance(true).validateCoordinate(350.0, 45.0, Double.NaN); // lon=350 invalid\n\n// after\ndouble lon = ((350.0 + 540) % 360) - 180; // -> -10\nGeographyValidator.instance(true).validateCoordinate(lon, 45.0, Double.NaN);","handlingStrategy":"validation","validationCode":"if (Double.isNaN(lon) || lon < -180.0 || lon > 180.0) {\n    lon = ((lon + 540) % 360) - 180; // normalize from [0,360) or other\n    if (Double.isNaN(lon) || lon < -180.0 || lon > 180.0) {\n        throw new IllegalArgumentException(\"longitude out of range: \" + lon);\n    }\n}\nGeographyValidator.instance(ignoreZ).validateCoordinate(lon, lat, z);","typeGuard":"static boolean isValidLongitude(double lon) {\n    return !Double.isNaN(lon) && lon >= -180.0 && lon <= 180.0;\n}","tryCatchPattern":null,"preventionTips":["Normalize longitudes from [0,360) to [-180,180) before validating.","Remember validateCoordinate takes (x=lon, y=lat) — GeographyValidator reads x as longitude.","Filter NaN longitudes if missing data should be skipped."],"tags":["geometry","validation","geographic","longitude","coordinate-bounds","libs-geo"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}