microg/GmsCore · error · IllegalArgumentException

invalid radius:

Error message

invalid radius: 

What it means

android.location.Geofence's builder throws IllegalArgumentException("invalid radius: " + radius) when checkRadius receives a radius <= 0. Geofences are defined as horizontal circles, so a positive finite radius in meters is mandatory.

Source

Thrown at play-services-location/core/system-api/src/main/java/android/location/Geofence.java:72

    /** @hide */
    public double getLatitude() {
        return mLatitude;
    }

    /** @hide */
    public double getLongitude() {
        return mLongitude;
    }

    /** @hide */
    public float getRadius() {
        return mRadius;
    }

    private static void checkRadius(float radius) {
        if (radius <= 0) {
            throw new IllegalArgumentException("invalid radius: " + radius);
        }
    }

    private static void checkLatLong(double latitude, double longitude) {
        if (latitude > 90.0 || latitude < -90.0) {
            throw new IllegalArgumentException("invalid latitude: " + latitude);
        }
        if (longitude > 180.0 || longitude < -180.0) {
            throw new IllegalArgumentException("invalid longitude: " + longitude);
        }
    }

    private static void checkType(int type) {
        if (type != TYPE_HORIZONTAL_CIRCLE) {
            throw new IllegalArgumentException("invalid type: " + type);
        }
    }

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Ensure the radius is > 0 before calling setRadius — reject or clamp invalid values at the config/UI layer
  2. Validate parsed/user input: require a finite, positive number in meters (typically >= 20m for reliability)
  3. Check the data source for unit conversion or uninitialized-variable bugs

Example fix

// before
Geofence geofence = new Geofence.Builder()
    .setRequestId(id)
    .setRadius(radiusFromConfig)
    .build();
// after
if (!(radiusFromConfig > 0f) || Float.isNaN(radiusFromConfig)) {
    throw new IllegalArgumentException("geofence radius must be positive meters");
}
Geofence geofence = new Geofence.Builder()
    .setRequestId(id)
    .setRadius(radiusFromConfig)
    .build();
Defensive patterns

Strategy: validation

Validate before calling

public static boolean isValidGeofenceRadius(float radius) {
    return Float.isFinite(radius) && radius > 0f;
}

Try / catch

try {
    Geofence g = new Geofence.Builder()
        .setRequestId(id).setCircularRegion(lat, lon, radius).build();
} catch (IllegalArgumentException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("invalid radius")) {
        reportBadConfig(id, radius);
    }
}

Prevention

When it happens

Trigger: Calling Geofence.Builder.setRadius(0f), a negative value, or NaN/Infinity-tainted values when constructing a geofence via the builder before create().

Common situations: Uninitialized or default-zero float fields feeding setRadius; parsing radius from user input or remote config without validation; unit confusion (feet vs meters) producing wrong magnitudes; division producing NaN.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06). Data as JSON: /api/errors/c943e44c908d0e67. Report an issue: GitHub.