quarkusio/quarkus · error · IllegalArgumentException

The longitude must be in [-180, 180]

Error message

The longitude must be in [-180, 180]

What it means

GeoPosition.of(double, double) constructs a geographic coordinate for GEO commands and validates that longitude lies within [-180, 180], the valid WGS-84 range Redis geospatial indexing accepts. Out-of-range longitudes throw this IllegalArgumentException at construction time.

Source

Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/geo/GeoPosition.java:23

 *
 * The exact limits, as specified by EPSG:900913 / EPSG:3785 / OSGEO:41001 are the following:
 * <ul>
 * <li>Valid longitudes are from -180 to 180 degrees.</li>
 * <li>Valid latitudes are from -85.05112878 to 85.05112878 degrees.</li>
 * </ul>
 */
public class GeoPosition {

    public final double longitude;
    public final double latitude;

    public static GeoPosition of(double longitude, double latitude) {
        return new GeoPosition(longitude, latitude);
    }

    private GeoPosition(double longitude, double latitude) {
        if (longitude < -180 || longitude > 180) {
            throw new IllegalArgumentException("The longitude must be in [-180, 180]");
        }
        if (latitude < -85.05112878 || latitude > 85.05112878) {
            throw new IllegalArgumentException("The latitude must be in [85.05112878, 85.05112878]");
        }
        this.longitude = longitude;
        this.latitude = latitude;
    }

    public double longitude() {
        return longitude;
    }

    public double latitude() {
        return latitude;
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Verify you pass (longitude, latitude) in that order — a common mistake is the reverse.
  2. Normalize longitude into [-180,180] before constructing (e.g. ((lon + 180) % 360 + 360) % 360 - 180).
  3. Validate parsed coordinates before calling GeoPosition.of and reject or fix invalid input at the boundary.

Example fix

// before
GeoPosition pos = GeoPosition.of(48.85, 2.35); // latitude passed as longitude -> throws
// after
GeoPosition pos = GeoPosition.of(2.35, 48.85); // (longitude, latitude)
Defensive patterns

Strategy: validation

Validate before calling

void checkLonLat(double lon, double lat) {
    if (lon < -180 || lon > 180) throw new IllegalArgumentException("longitude out of range: " + lon);
    if (lat < -85.05112878 || lat > 85.05112878) throw new IllegalArgumentException("latitude out of range: " + lat);
}

Type guard

boolean isValidLongitude(double lon) { return Double.isFinite(lon) && lon >= -180.0 && lon <= 180.0; }

Try / catch

try { return GeoPosition.of(lon, lat); } catch (IllegalArgumentException e) { log.warn("Invalid coordinate lon={} lat={}", lon, lat, e); throw e; }

Prevention

When it happens

Trigger: Calling GeoPosition.of(181, 45) or any longitude outside [-180,180] — e.g. swapping arguments and passing a latitude in the longitude slot, or using degrees-minutes-seconds values not converted to decimal degrees.

Common situations: Parsing user-supplied or third-party coordinates without range checks; argument-order swaps (lat/lon confusion, the most common geo bug); data from CSV feeds with formatting errors; geocoding services returning unexpected values.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/952b9bd2bc7004bc. Report an issue: GitHub.