microg/GmsCore · error · IllegalArgumentException

maxUpdates must be greater than 0

Error message

maxUpdates must be greater than 0

What it means

LocationRequest.Builder.setMaxUpdates() validates that the requested maximum number of location updates is a positive integer. The library throws this IllegalArgumentException immediately when maxUpdates <= 0, because zero or negative update counts are meaningless for a location request.

Source

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

         * The default value is 0.
         */
        @NonNull
        public Builder setMaxUpdateDelayMillis(long maxUpdateDelayMillis) {
            if (maxUpdateDelayMillis < 0) throw new IllegalArgumentException("maxUpdateDelayMillis must be greater than or equal to 0");
            this.maxUpdateDelayMillis = maxUpdateDelayMillis;
            return this;
        }

        /**
         * Sets the maximum number of updates delivered to this request. A location request will not receive any locations after the
         * maximum number of updates has been reached, and will be removed shortly thereafter. A value of {@link Integer#MAX_VALUE}
         * implies an unlimited number of updates.
         * <p>
         * The default value is {@link Integer#MAX_VALUE}.
         */
        @NonNull
        public Builder setMaxUpdates(int maxUpdates) {
            if (maxUpdates <= 0) throw new IllegalArgumentException("maxUpdates must be greater than 0");
            this.maxUpdates = maxUpdates;
            return this;
        }

        /**
         * Sets the minimum distance required between consecutive location updates. If a derived location update is not at least
         * the specified distance away from the previous location update delivered to the client, it will not be delivered. This may
         * also allow additional power savings under some circumstances.
         * <p>
         * The default value is 0.
         */
        @NonNull
        public Builder setMinUpdateDistanceMeters(float minUpdateDistanceMeters) {
            if (minUpdateDistanceMeters < 0) throw new IllegalArgumentException("minUpdateDistanceMeters must be greater than or equal to 0");
            this.minUpdateDistanceMeters = minUpdateDistanceMeters;
            return this;
        }

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Pass a positive integer to setMaxUpdates (e.g. 1, or Integer.MAX_VALUE for unlimited).
  2. Validate the value before calling the builder and fall back to a sane default.
  3. Check the source of the limit (config, user input) to ensure it is populated.
  4. If unlimited updates are intended, omit setMaxUpdates entirely (default is Integer.MAX_VALUE).

Example fix

// before
LocationRequest request = new LocationRequest.Builder(interval)
    .setMaxUpdates(0)
    .build();
// after
LocationRequest request = new LocationRequest.Builder(interval)
    .setMaxUpdates(Math.max(1, requestedUpdates))
    .build();
Defensive patterns

Strategy: validation

Validate before calling

if (maxUpdates <= 0) { throw new IllegalArgumentException("maxUpdates must be > 0"); }
builder.setMaxUpdates(maxUpdates);

Try / catch

try {
    builder.setMaxUpdates(maxUpdates);
} catch (IllegalArgumentException e) {
    builder.setMaxUpdates(Integer.MAX_VALUE); // fallback to unlimited
}

Prevention

When it happens

Trigger: Calling LocationRequest.Builder.setMaxUpdates(int) with 0, a negative value, or an uninitialized/computed value that resolved to <= 0.

Common situations: Hardcoding 0 by mistake, passing a user-supplied or config-driven limit that defaults to 0, or arithmetic that yields a negative count before building the request.

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