{"record":{"id":"b0ee546dab4ffc8e","repo":"microg/GmsCore","slug":"illegal-max-wait-time","errorCode":null,"errorMessage":"illegal max wait time: ","messagePattern":"illegal max wait time: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-location/src/main/java/com/google/android/gms/location/LocationRequest.java","lineNumber":458,"sourceCode":"    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;\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     */","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/src/main/java/com/google/android/gms/location/LocationRequest.java#L440-L476","documentation":"LocationRequest.setMaxWaitTime(long) throws IllegalArgumentException when maxWaitTimeMillis is negative. Max wait time caps how long location updates may be batched/delayed for delivery, so a negative cap is invalid and rejected before assignment. Notably this setter is also invoked during deserialization by readLocationRequest, so a negative value read from a serialized LocationRequest (e.g. via Bundle/intent extras) also throws.","triggerScenarios":"Calling the deprecated setMaxWaitTime() with a negative long; or readLocationRequest deserializing a stored request whose maxWaitTimeMillis was persisted as negative.","commonSituations":"Sentinel -1 defaults persisted into Bundles and later read back; arithmetic on wait time going negative; hand-crafted serialized requests passed via PendingIntent/intent extras.","solutions":["Ensure the value is >= 0 before calling: clamp with Math.max(0, maxWaitTimeMillis).","Audit code that persists LocationRequest parameters (Bundles/intents) for negative sentinel values.","Switch to LocationRequest.Builder.setMaxUpdateDelayMillis() for batched updates."],"exampleFix":"// before\nrequest.setMaxWaitTime(maxWaitTimeMillis); // throws if negative\n// after\nif (maxWaitTimeMillis >= 0) {\n    request.setMaxWaitTime(maxWaitTimeMillis);\n} else {\n    request.setMaxWaitTime(0);\n}","handlingStrategy":"validation","validationCode":"// Java\npublic static long sanitizeMaxWaitTime(long maxWaitTimeMillis) {\n    return Math.max(0L, maxWaitTimeMillis);\n}\n// request.setMaxWaitTime(sanitizeMaxWaitTime(raw));","typeGuard":"static boolean isValidMaxWaitTime(long millis) { return millis >= 0; }","tryCatchPattern":"// Java\ntry {\n    request.setMaxWaitTime(maxWaitTimeMillis);\n} catch (IllegalArgumentException e) {\n    Log.w(\"LocationReq\", \"Invalid maxWaitTime \" + maxWaitTimeMillis + \", using 0\", e);\n    request.setMaxWaitTime(0);\n}","preventionTips":["Audit any code that stores LocationRequest parameters in Bundles/intents for negative sentinel values that later throw via readLocationRequest.","Clamp persisted values when reading them back before re-applying them.","Use Builder.setMaxUpdateDelayMillis for batching instead of the deprecated setter."],"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"}