{"record":{"id":"19fe0c0b90c81e80","repo":"microg/GmsCore","slug":"intervalmillis-must-be-greater-than-0","errorCode":null,"errorMessage":"intervalMillis must be greater than 0","messagePattern":"intervalMillis 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":680,"sourceCode":"        }\n\n        @NonNull\n        @PublicApi(exclude = true)\n        @RequiresPermission(anyOf = {\"android.permission.WRITE_SECURE_SETTINGS\", \"android.permission.LOCATION_BYPASS\"})\n        public Builder setBypass(boolean bypass) {\n            this.bypass = bypass;\n            return this;\n        }\n\n        /**\n         * Sets the duration of this request. A location request will not receive any locations after it has expired, and will be\n         * removed shortly thereafter. A value of {@link Long#MAX_VALUE} implies an infinite duration.\n         * <p>\n         * The default value is {@link Long#MAX_VALUE}.\n         */\n        @NonNull\n        public Builder setDurationMillis(long durationMillis) {\n            if (durationMillis <= 0) throw new IllegalArgumentException(\"intervalMillis must be greater than 0\");\n            this.durationMillis = durationMillis;\n            return this;\n        }\n\n        /**\n         * Sets the {@link Granularity} of locations returned for this request. This controls whether fine or coarse locations may be\n         * returned.\n         * <p>\n         * The default value is {@link Granularity#GRANULARITY_PERMISSION_LEVEL}.\n         */\n        @NonNull\n        public Builder setGranularity(@Granularity int granularity) {\n            GranularityUtil.checkValidGranularity(granularity);\n            this.granularity = granularity;\n            return this;\n        }\n\n        /**","sourceCodeStart":662,"sourceCodeEnd":698,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/src/main/java/com/google/android/gms/location/LocationRequest.java#L662-L698","documentation":"setDurationMillis validates that the request duration is strictly positive. A duration of 0 or less means the request would never receive updates, so the builder rejects it. Note the misleading message text says 'intervalMillis' but the checked value is durationMillis.","triggerScenarios":"Calling builder.setDurationMillis(0) or any negative value, e.g. setDurationMillis(-1) or setDurationMillis(0) intending to mean 'no duration limit' instead of using Long.MAX_VALUE (the default).","commonSituations":"Developers passing 0 thinking it disables the duration limit; computing duration from a deadline that already passed (deadline - now <= 0); copying a value from code that used 0 as a sentinel for 'infinite'.","solutions":["Pass a positive duration; to keep the request alive indefinitely, simply do not call setDurationMillis (default is Long.MAX_VALUE).","Clamp computed durations: Math.max(1, deadlineMillis - System.currentTimeMillis()).","If 0 was meant as 'unlimited', remove the call rather than setting 0."],"exampleFix":"// before\nbuilder.setDurationMillis(0); // intended 'no limit'\n// after\nbuilder.setDurationMillis(Long.MAX_VALUE); // or omit the call entirely (default)","handlingStrategy":"validation","validationCode":"public static boolean isValidDuration(long durationMillis) {\n    return durationMillis > 0;\n}\nif (!isValidDuration(duration)) duration = Long.MAX_VALUE; // treat <=0 as infinite","typeGuard":"static boolean isPositive(long v) { return v > 0; }","tryCatchPattern":"try {\n    return builder.setDurationMillis(duration);\n} catch (IllegalArgumentException e) {\n    if (!e.getMessage().contains(\"greater than 0\")) throw e;\n    return builder; // keep default Long.MAX_VALUE duration\n}","preventionTips":["Remember 0 is invalid here — 'unlimited' means omitting the call or Long.MAX_VALUE.","When deriving duration from a deadline, check the deadline is in the future before subtracting.","Note the exception message says 'intervalMillis' even though it's about duration — match on the setter name, not just the message."],"tags":["android","location","illegal-argument","validation"],"backgroundTag":"argument-out-of-range","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"}