{"record":{"id":"30d2913de7886d67","repo":"microg/GmsCore","slug":"intervalmillis-must-be-greater-than-or-equal-to-0","errorCode":null,"errorMessage":"intervalMillis must be greater than or equal to 0","messagePattern":"intervalMillis must be greater than or equal to 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-location/src/main/java/com/google/android/gms/location/LocationRequest.java","lineNumber":441,"sourceCode":"    /**\n     * @deprecated Use {@link LocationRequest.Builder#setMinUpdateIntervalMillis(long)} instead. May be removed in a future release.\n     */\n    @Deprecated\n    @NonNull\n    public LocationRequest setFastestInterval(long fastestIntervalMillis) throws IllegalArgumentException {\n        if (fastestIntervalMillis < 0) throw new IllegalArgumentException(\"illegal fastest interval: \" + fastestIntervalMillis);\n        this.minUpdateIntervalMillis = fastestIntervalMillis;\n        explicitFastestInterval = true; // FIXME: Remove\n        return this;\n    }\n\n    /**\n     * @deprecated Use {@link LocationRequest.Builder#setIntervalMillis(long)} instead. May be removed in a future release.\n     */\n    @Deprecated\n    @NonNull\n    public LocationRequest setInterval(long intervalMillis) throws IllegalArgumentException {\n        if (intervalMillis < 0) throw new IllegalArgumentException(\"intervalMillis must be greater than or equal to 0\");\n        if (this.minUpdateIntervalMillis == this.intervalMillis / 6) {\n            this.minUpdateIntervalMillis = intervalMillis / 6;\n        }\n        if (this.maxUpdateAgeMillis == this.intervalMillis) {\n            this.maxUpdateAgeMillis = intervalMillis;\n        }\n        this.intervalMillis = intervalMillis;\n        return this;\n    }\n\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;","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/src/main/java/com/google/android/gms/location/LocationRequest.java#L423-L459","documentation":"LocationRequest.setInterval(long) throws IllegalArgumentException when intervalMillis is negative. The interval is the desired interval between location updates; negative values are invalid because the setter also derives minUpdateIntervalMillis (interval/6) and maxUpdateAgeMillis from it. The library rejects the value synchronously before mutating state.","triggerScenarios":"Calling the deprecated LocationRequest.setInterval() with a negative long, e.g. setInterval(-1), or with a value computed/parsed as negative.","commonSituations":"Sentinel -1 for 'unspecified' interval; unit mixups (seconds vs millis) yielding negative after conversion math; negative values from server or user config; migrating old code that used -1 defaults.","solutions":["Validate the interval is >= 0 before calling setInterval; clamp with Math.max(0, intervalMillis).","If you used -1 as a sentinel, branch around the call instead of passing it.","Move to LocationRequest.Builder(intervalMillis) so interval and derived fields are handled consistently."],"exampleFix":"// before\nLocationRequest request = new LocationRequest().setInterval(-1); // throws\n// after\nlong intervalMillis = rawInterval < 0 ? 10_000L : rawInterval;\nLocationRequest request = new LocationRequest.Builder(intervalMillis).build();","handlingStrategy":"validation","validationCode":"// Java\npublic static long sanitizeInterval(long intervalMillis) {\n    return Math.max(0L, intervalMillis);\n}\n// request.setInterval(sanitizeInterval(rawInterval));","typeGuard":"static boolean isValidIntervalMillis(long millis) { return millis >= 0; }","tryCatchPattern":"// Java\ntry {\n    request.setInterval(intervalMillis);\n} catch (IllegalArgumentException e) {\n    Log.w(\"LocationReq\", \"Invalid interval, falling back to 10s\");\n    request.setInterval(10_000L);\n}","preventionTips":["Keep interval units in one place (always millis) to avoid conversion math going negative.","Validate user/server-provided intervals at config-load time, not at request-build time.","Replace deprecated setInterval with LocationRequest.Builder(intervalMillis)."],"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-14T05:17:10.506Z"}