{"record":{"id":"21af863f38a443e1","repo":"microg/GmsCore","slug":"illegal-fastest-interval","errorCode":null,"errorMessage":"illegal fastest interval: ","messagePattern":"illegal fastest interval: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-location/src/main/java/com/google/android/gms/location/LocationRequest.java","lineNumber":429,"sourceCode":"\n    /**\n     * @deprecated Use {@link LocationRequest.Builder#setDurationMillis(long)} instead. Using this method will express the expiration time in\n     * terms of duration, which may give unexpected results. May be removed in a future release.\n     */\n    @Deprecated\n    @NonNull\n    public LocationRequest setExpirationTime(long elapsedRealtime) {\n        this.durationMillis = Math.max(1, elapsedRealtime - SystemClock.elapsedRealtime());\n        return this;\n    }\n\n    /**\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        }","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/src/main/java/com/google/android/gms/location/LocationRequest.java#L411-L447","documentation":"LocationRequest.setFastestInterval(long) throws IllegalArgumentException when the supplied fastestIntervalMillis is negative. The fastest interval defines the minimum time between location updates, so a negative value is meaningless and rejected before the field is set. This is a pre-call validation guard in the library, not an async failure.","triggerScenarios":"Calling the deprecated LocationRequest.setFastestInterval() with a negative long, e.g. setFastestInterval(-1000), or passing a computed variable that underflowed or was initialized to -1 as a sentinel.","commonSituations":"Using -1 as a 'default/unset' sentinel for the interval; subtracting from a small interval causing long underflow; porting old code where -1 meant 'automatic'; config values parsed from negative settings.","solutions":["Clamp or reject negative values before calling setFastestInterval: use Math.max(0, intervalMillis).","Use -1 only as 'unset' in your own code and skip the call when it is -1.","Migrate to the Builder API: new LocationRequest.Builder(intervalMillis).setMinUpdateIntervalMillis(...) which validates centrally."],"exampleFix":"// before\nLocationRequest request = new LocationRequest()\n    .setInterval(intervalMillis)\n    .setFastestInterval(fastestIntervalMillis); // throws if negative\n// after\nLocationRequest request = new LocationRequest.Builder(intervalMillis)\n    .setMinUpdateIntervalMillis(Math.max(0, fastestIntervalMillis))\n    .build();","handlingStrategy":"validation","validationCode":"// Java\npublic static void checkFastestInterval(long fastestIntervalMillis) {\n    if (fastestIntervalMillis < 0) {\n        throw new IllegalArgumentException(\"fastestIntervalMillis must be >= 0, got \" + fastestIntervalMillis);\n    }\n}\n// call checkFastestInterval(v) before request.setFastestInterval(v)","typeGuard":"static boolean isValidInterval(long millis) { return millis >= 0; }","tryCatchPattern":"// Java\ntry {\n    request.setFastestInterval(fastestIntervalMillis);\n} catch (IllegalArgumentException e) {\n    Log.w(\"LocationReq\", \"Invalid fastest interval \" + fastestIntervalMillis + \", using default\", e);\n    request.setFastestInterval(0);\n}","preventionTips":["Never use -1 as an interval sentinel; use 0 or a separate boolean flag.","Clamp all externally-sourced interval values with Math.max(0, value) before applying them.","Prefer LocationRequest.Builder, which centralizes validation with clearer messages."],"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"}