microg/GmsCore · error · IllegalArgumentException

invalid numUpdates: {maxUpdates}

Error message

invalid numUpdates: {maxUpdates}

What it means

LocationRequest.setNumUpdates(int) throws IllegalArgumentException when maxUpdates is <= 0. The number of updates must be a positive integer since it counts how many location results to deliver; zero would mean no updates and negatives are nonsensical. The library rejects the value before setting the field.

Source

Thrown at play-services-location/src/main/java/com/google/android/gms/location/LocationRequest.java:469

    /**
     * @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.
     */
    @Deprecated
    @NonNull
    public LocationRequest setPriority(@Priority int priority) {
        PriorityUtil.checkValidPriority(priority);
        this.priority = priority;
        return this;
    }

    /**
     * @deprecated Use {@link LocationRequest.Builder#setMinUpdateDistanceMeters(float)} instead. May be removed in a future release.
     */

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Guard with if (maxUpdates > 0) before calling; treat 0 as 'skip requesting updates'.
  2. If 'unlimited' was intended, do not use setNumUpdates at all (the field defaults to Integer.MAX_VALUE).
  3. Migrate to LocationRequest.Builder.setMaxUpdates(int) with the same positive-only constraint.

Example fix

// before
request.setNumUpdates(updateCount); // throws when updateCount <= 0
// after
if (updateCount > 0) {
    request.setNumUpdates(updateCount);
} // else: leave default (unlimited) or skip the request
Defensive patterns

Strategy: validation

Validate before calling

// Java
public static void checkNumUpdates(int maxUpdates) {
    if (maxUpdates <= 0) {
        throw new IllegalArgumentException("maxUpdates must be > 0, got " + maxUpdates);
    }
}
// if (maxUpdates > 0) request.setNumUpdates(maxUpdates);

Type guard

static boolean isValidNumUpdates(int n) { return n > 0; }

Try / catch

// Java
try {
    request.setNumUpdates(maxUpdates);
} catch (IllegalArgumentException e) {
    Log.w("LocationReq", "Invalid numUpdates " + maxUpdates + ", leaving unlimited");
}

Prevention

When it happens

Trigger: Calling the deprecated setNumUpdates() with 0 or a negative int, e.g. setNumUpdates(0) or setNumUpdates(numUpdates) where numUpdates was computed as zero.

Common situations: Default int (0) passed accidentally; a counter that already reached zero; user/config input of 0 interpreted as 'no limit' but the API requires a positive count.

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/bb315b7de59cb276. Report an issue: GitHub.