{"record":{"id":"a6b4001fe700fa37","repo":"microg/GmsCore","slug":"maxupdates-must-be-greater-than-0","errorCode":null,"errorMessage":"maxUpdates must be greater than 0","messagePattern":"maxUpdates must be greater than 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-location/src/main/java/com/google/android/gms/location/LocationRequest.java","lineNumber":764,"sourceCode":"         * The default value is 0.\n         */\n        @NonNull\n        public Builder setMaxUpdateDelayMillis(long maxUpdateDelayMillis) {\n            if (maxUpdateDelayMillis < 0) throw new IllegalArgumentException(\"maxUpdateDelayMillis must be greater than or equal to 0\");\n            this.maxUpdateDelayMillis = maxUpdateDelayMillis;\n            return this;\n        }\n\n        /**\n         * Sets the maximum number of updates delivered to this request. A location request will not receive any locations after the\n         * maximum number of updates has been reached, and will be removed shortly thereafter. A value of {@link Integer#MAX_VALUE}\n         * implies an unlimited number of updates.\n         * <p>\n         * The default value is {@link Integer#MAX_VALUE}.\n         */\n        @NonNull\n        public Builder setMaxUpdates(int maxUpdates) {\n            if (maxUpdates <= 0) throw new IllegalArgumentException(\"maxUpdates must be greater than 0\");\n            this.maxUpdates = maxUpdates;\n            return this;\n        }\n\n        /**\n         * Sets the minimum distance required between consecutive location updates. If a derived location update is not at least\n         * the specified distance away from the previous location update delivered to the client, it will not be delivered. This may\n         * also allow additional power savings under some circumstances.\n         * <p>\n         * The default value is 0.\n         */\n        @NonNull\n        public Builder setMinUpdateDistanceMeters(float minUpdateDistanceMeters) {\n            if (minUpdateDistanceMeters < 0) throw new IllegalArgumentException(\"minUpdateDistanceMeters must be greater than or equal to 0\");\n            this.minUpdateDistanceMeters = minUpdateDistanceMeters;\n            return this;\n        }\n","sourceCodeStart":746,"sourceCodeEnd":782,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/src/main/java/com/google/android/gms/location/LocationRequest.java#L746-L782","documentation":"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.","triggerScenarios":"Calling LocationRequest.Builder.setMaxUpdates(int) with 0, a negative value, or an uninitialized/computed value that resolved to <= 0.","commonSituations":"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.","solutions":["Pass a positive integer to setMaxUpdates (e.g. 1, or Integer.MAX_VALUE for unlimited).","Validate the value before calling the builder and fall back to a sane default.","Check the source of the limit (config, user input) to ensure it is populated.","If unlimited updates are intended, omit setMaxUpdates entirely (default is Integer.MAX_VALUE)."],"exampleFix":"// before\nLocationRequest request = new LocationRequest.Builder(interval)\n    .setMaxUpdates(0)\n    .build();\n// after\nLocationRequest request = new LocationRequest.Builder(interval)\n    .setMaxUpdates(Math.max(1, requestedUpdates))\n    .build();","handlingStrategy":"validation","validationCode":"if (maxUpdates <= 0) { throw new IllegalArgumentException(\"maxUpdates must be > 0\"); }\nbuilder.setMaxUpdates(maxUpdates);","typeGuard":null,"tryCatchPattern":"try {\n    builder.setMaxUpdates(maxUpdates);\n} catch (IllegalArgumentException e) {\n    builder.setMaxUpdates(Integer.MAX_VALUE); // fallback to unlimited\n}","preventionTips":["Validate positive-integer inputs before building LocationRequest","Use Math.max(1, value) when the count is computed","Remember Integer.MAX_VALUE means unlimited; omit the setter if that's desired"],"tags":["android","location","argument-validation"],"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-14T05:17:10.506Z"}