microg/GmsCore · error · IllegalArgumentException
intervalMillis must be greater than or equal to 0
Error message
intervalMillis must be greater than or equal to 0
What it means
LocationRequest.setInterval(long) throws IllegalArgumentException when intervalMillis is negative. The interval is the desired interval between location updates; negative values are invalid because the setter also derives minUpdateIntervalMillis (interval/6) and maxUpdateAgeMillis from it. The library rejects the value synchronously before mutating state.
Source
Thrown at play-services-location/src/main/java/com/google/android/gms/location/LocationRequest.java:441
/**
* @deprecated Use {@link LocationRequest.Builder#setMinUpdateIntervalMillis(long)} instead. May be removed in a future release.
*/
@Deprecated
@NonNull
public LocationRequest setFastestInterval(long fastestIntervalMillis) throws IllegalArgumentException {
if (fastestIntervalMillis < 0) throw new IllegalArgumentException("illegal fastest interval: " + fastestIntervalMillis);
this.minUpdateIntervalMillis = fastestIntervalMillis;
explicitFastestInterval = true; // FIXME: Remove
return this;
}
/**
* @deprecated Use {@link LocationRequest.Builder#setIntervalMillis(long)} instead. May be removed in a future release.
*/
@Deprecated
@NonNull
public LocationRequest setInterval(long intervalMillis) throws IllegalArgumentException {
if (intervalMillis < 0) throw new IllegalArgumentException("intervalMillis must be greater than or equal to 0");
if (this.minUpdateIntervalMillis == this.intervalMillis / 6) {
this.minUpdateIntervalMillis = intervalMillis / 6;
}
if (this.maxUpdateAgeMillis == this.intervalMillis) {
this.maxUpdateAgeMillis = intervalMillis;
}
this.intervalMillis = intervalMillis;
return this;
}
/**
* @deprecated Use {@link LocationRequest.Builder#setMaxUpdateDelayMillis(long)} instead. May be removed in a future release.
*/
@Deprecated
@NonNull
public LocationRequest setMaxWaitTime(long maxWaitTimeMillis) throws IllegalArgumentException {
if (maxWaitTimeMillis < 0) throw new IllegalArgumentException("illegal max wait time: " + maxWaitTimeMillis);
maxUpdateDelayMillis = maxWaitTimeMillis;View on GitHub (pinned to 157c9d86ac)
Solutions
- Validate the interval is >= 0 before calling setInterval; clamp with Math.max(0, intervalMillis).
- If you used -1 as a sentinel, branch around the call instead of passing it.
- Move to LocationRequest.Builder(intervalMillis) so interval and derived fields are handled consistently.
Example fix
// before LocationRequest request = new LocationRequest().setInterval(-1); // throws // after long intervalMillis = rawInterval < 0 ? 10_000L : rawInterval; LocationRequest request = new LocationRequest.Builder(intervalMillis).build();
Defensive patterns
Strategy: validation
Validate before calling
// Java
public static long sanitizeInterval(long intervalMillis) {
return Math.max(0L, intervalMillis);
}
// request.setInterval(sanitizeInterval(rawInterval)); Type guard
static boolean isValidIntervalMillis(long millis) { return millis >= 0; } Try / catch
// Java
try {
request.setInterval(intervalMillis);
} catch (IllegalArgumentException e) {
Log.w("LocationReq", "Invalid interval, falling back to 10s");
request.setInterval(10_000L);
} Prevention
- Keep interval units in one place (always millis) to avoid conversion math going negative.
- Validate user/server-provided intervals at config-load time, not at request-build time.
- Replace deprecated setInterval with LocationRequest.Builder(intervalMillis).
When it happens
Trigger: Calling the deprecated LocationRequest.setInterval() with a negative long, e.g. setInterval(-1), or with a value computed/parsed as negative.
Common situations: Sentinel -1 for 'unspecified' interval; unit mixups (seconds vs millis) yielding negative after conversion math; negative values from server or user config; migrating old code that used -1 defaults.
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
- illegal fastest interval:
- illegal max wait time:
- invalid numUpdates: {maxUpdates}
- invalid displacement: {smallestDisplacementMeters}
- durationMillis must be greater than 0
AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06).
Data as JSON: /api/errors/30d2913de7886d67.
Report an issue: GitHub.