microg/GmsCore · error · IllegalArgumentException
illegal max wait time:
Error message
illegal max wait time:
What it means
LocationRequest.setMaxWaitTime(long) throws IllegalArgumentException when maxWaitTimeMillis is negative. Max wait time caps how long location updates may be batched/delayed for delivery, so a negative cap is invalid and rejected before assignment. Notably this setter is also invoked during deserialization by readLocationRequest, so a negative value read from a serialized LocationRequest (e.g. via Bundle/intent extras) also throws.
Source
Thrown at play-services-location/src/main/java/com/google/android/gms/location/LocationRequest.java:458
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;
return this;
}
/**
* @deprecated Use {@link LocationRequest.Builder#setMaxUpdates(int)} instead. May be removed in a future release.
*/
@Deprecated
@NonNull
public LocationRequest setNumUpdates(int maxUpdates) throws IllegalArgumentException {
if (maxUpdates <= 0) throw new IllegalArgumentException("invalid numUpdates: " + maxUpdates);
this.maxUpdates = maxUpdates;
return this;
}
/**
* @deprecated Use {@link LocationRequest.Builder#setPriority(int)} instead. May be removed in a future release.
*/View on GitHub (pinned to 157c9d86ac)
Solutions
- Ensure the value is >= 0 before calling: clamp with Math.max(0, maxWaitTimeMillis).
- Audit code that persists LocationRequest parameters (Bundles/intents) for negative sentinel values.
- Switch to LocationRequest.Builder.setMaxUpdateDelayMillis() for batched updates.
Example fix
// before
request.setMaxWaitTime(maxWaitTimeMillis); // throws if negative
// after
if (maxWaitTimeMillis >= 0) {
request.setMaxWaitTime(maxWaitTimeMillis);
} else {
request.setMaxWaitTime(0);
} Defensive patterns
Strategy: validation
Validate before calling
// Java
public static long sanitizeMaxWaitTime(long maxWaitTimeMillis) {
return Math.max(0L, maxWaitTimeMillis);
}
// request.setMaxWaitTime(sanitizeMaxWaitTime(raw)); Type guard
static boolean isValidMaxWaitTime(long millis) { return millis >= 0; } Try / catch
// Java
try {
request.setMaxWaitTime(maxWaitTimeMillis);
} catch (IllegalArgumentException e) {
Log.w("LocationReq", "Invalid maxWaitTime " + maxWaitTimeMillis + ", using 0", e);
request.setMaxWaitTime(0);
} Prevention
- Audit any code that stores LocationRequest parameters in Bundles/intents for negative sentinel values that later throw via readLocationRequest.
- Clamp persisted values when reading them back before re-applying them.
- Use Builder.setMaxUpdateDelayMillis for batching instead of the deprecated setter.
When it happens
Trigger: Calling the deprecated setMaxWaitTime() with a negative long; or readLocationRequest deserializing a stored request whose maxWaitTimeMillis was persisted as negative.
Common situations: Sentinel -1 defaults persisted into Bundles and later read back; arithmetic on wait time going negative; hand-crafted serialized requests passed via PendingIntent/intent extras.
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:
- intervalMillis must be greater than or equal to 0
- 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/b0ee546dab4ffc8e.
Report an issue: GitHub.