{"record":{"id":"bb315b7de59cb276","repo":"microg/GmsCore","slug":"invalid-numupdates-maxupdates","errorCode":null,"errorMessage":"invalid numUpdates: {maxUpdates}","messagePattern":"invalid numUpdates: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-location/src/main/java/com/google/android/gms/location/LocationRequest.java","lineNumber":469,"sourceCode":"\n    /**\n     * @deprecated Use {@link LocationRequest.Builder#setMaxUpdateDelayMillis(long)} instead. May be removed in a future release.\n     */\n    @Deprecated\n    @NonNull\n    public LocationRequest setMaxWaitTime(long maxWaitTimeMillis) throws IllegalArgumentException {\n        if (maxWaitTimeMillis < 0) throw new IllegalArgumentException(\"illegal max wait time: \" + maxWaitTimeMillis);\n        maxUpdateDelayMillis = maxWaitTimeMillis;\n        return this;\n    }\n\n    /**\n     * @deprecated Use {@link LocationRequest.Builder#setMaxUpdates(int)} instead. May be removed in a future release.\n     */\n    @Deprecated\n    @NonNull\n    public LocationRequest setNumUpdates(int maxUpdates) throws IllegalArgumentException {\n        if (maxUpdates <= 0) throw new IllegalArgumentException(\"invalid numUpdates: \" + maxUpdates);\n        this.maxUpdates = maxUpdates;\n        return this;\n    }\n\n    /**\n     * @deprecated Use {@link LocationRequest.Builder#setPriority(int)} instead. May be removed in a future release.\n     */\n    @Deprecated\n    @NonNull\n    public LocationRequest setPriority(@Priority int priority) {\n        PriorityUtil.checkValidPriority(priority);\n        this.priority = priority;\n        return this;\n    }\n\n    /**\n     * @deprecated Use {@link LocationRequest.Builder#setMinUpdateDistanceMeters(float)} instead. May be removed in a future release.\n     */","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/src/main/java/com/google/android/gms/location/LocationRequest.java#L451-L487","documentation":"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.","triggerScenarios":"Calling the deprecated setNumUpdates() with 0 or a negative int, e.g. setNumUpdates(0) or setNumUpdates(numUpdates) where numUpdates was computed as zero.","commonSituations":"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.","solutions":["Guard with if (maxUpdates > 0) before calling; treat 0 as 'skip requesting updates'.","If 'unlimited' was intended, do not use setNumUpdates at all (the field defaults to Integer.MAX_VALUE).","Migrate to LocationRequest.Builder.setMaxUpdates(int) with the same positive-only constraint."],"exampleFix":"// before\nrequest.setNumUpdates(updateCount); // throws when updateCount <= 0\n// after\nif (updateCount > 0) {\n    request.setNumUpdates(updateCount);\n} // else: leave default (unlimited) or skip the request","handlingStrategy":"validation","validationCode":"// Java\npublic static void checkNumUpdates(int maxUpdates) {\n    if (maxUpdates <= 0) {\n        throw new IllegalArgumentException(\"maxUpdates must be > 0, got \" + maxUpdates);\n    }\n}\n// if (maxUpdates > 0) request.setNumUpdates(maxUpdates);","typeGuard":"static boolean isValidNumUpdates(int n) { return n > 0; }","tryCatchPattern":"// Java\ntry {\n    request.setNumUpdates(maxUpdates);\n} catch (IllegalArgumentException e) {\n    Log.w(\"LocationReq\", \"Invalid numUpdates \" + maxUpdates + \", leaving unlimited\");\n}","preventionTips":["Remember 0 means 'zero updates' here, not 'unlimited'; the default field value is already unlimited.","Guard decrementing counters so they never pass 0 into the setter.","Use Builder.setMaxUpdates(n) with a positive-only constraint in your wrapper API."],"tags":["android","location","illegal-argument","deprecated-api"],"backgroundTag":"invalid-argument-value","analyzedSha":"157c9d86ac46c195a86c2f15ab55c84036223f95","analyzedAt":"2026-09-06T17:27:33.892Z","contentChangedAt":"2026-09-06T17:27:33.892Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}