{"record":{"id":"8b02cda6c5d1a38a","repo":"microg/GmsCore","slug":"maxupdateagemillis-must-be-greater-than-0","errorCode":null,"errorMessage":"maxUpdateAgeMillis must be greater than 0","messagePattern":"maxUpdateAgeMillis 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/LastLocationRequest.java","lineNumber":107,"sourceCode":"\n        /**\n         * Sets the {@link Granularity} of locations returned for this request. This controls whether fine or coarse locations may be returned.\n         * <p>\n         * The default value is {@link Granularity#GRANULARITY_PERMISSION_LEVEL}.\n         */\n        public LastLocationRequest.Builder setGranularity(@Granularity int granularity) {\n            GranularityUtil.checkValidGranularity(granularity);\n            this.granularity = granularity;\n            return this;\n        }\n\n        /**\n         * Sets the maximum age of any location returned for this request. A value of {@link Long#MAX_VALUE} represents an effectively unbounded maximum age.\n         * <p>\n         * The default value is {@link Long#MAX_VALUE}.\n         */\n        public LastLocationRequest.Builder setMaxUpdateAgeMillis(long maxUpdateAgeMillis) {\n            if (maxUpdateAgeMillis <= 0) throw new IllegalArgumentException(\"maxUpdateAgeMillis must be greater than 0\");\n            this.maxUpdateAgeMillis = maxUpdateAgeMillis;\n            return this;\n        }\n\n        /**\n         * Builds a new {@link LastLocationRequest}.\n         */\n        public LastLocationRequest build() {\n            LastLocationRequest request = new LastLocationRequest();\n            request.maxUpdateAgeMillis = maxUpdateAgeMillis;\n            request.granularity = granularity;\n            request.bypass = bypass;\n            request.moduleId = moduleId;\n            request.impersonation = impersonation;\n            return request;\n        }\n    }\n","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/src/main/java/com/google/android/gms/location/LastLocationRequest.java#L89-L125","documentation":"LastLocationRequest.Builder.setMaxUpdateAgeMillis() sets the maximum acceptable age of a returned location; only strictly positive values are meaningful, so the builder throws IllegalArgumentException for values <= 0.","triggerScenarios":"Calling setMaxUpdateAgeMillis(0) or any negative value (including accidentally passing Long.MIN_VALUE or an unset/default sentinel like -1 from config).","commonSituations":"Passing a config value defaulting to -1 or 0; integer overflow when computing the age from seconds; mixing up 'unbounded' (Long.MAX_VALUE) with 0.","solutions":["Pass a positive millisecond value (e.g. 10000 for 10 seconds)","Use Long.MAX_VALUE for an effectively unbounded maximum age","Clamp or validate config-derived values before calling the setter"],"exampleFix":"// before\nlong age = config.getLong(\"maxAge\", 0); // 0 default\nbuilder.setMaxUpdateAgeMillis(age); // throws\n// after\nlong age = config.getLong(\"maxAge\", 10000L);\nif (age > 0) builder.setMaxUpdateAgeMillis(age);","handlingStrategy":"validation","validationCode":"if (maxUpdateAgeMillis <= 0) {\n    maxUpdateAgeMillis = Long.MAX_VALUE; // or a sensible default like 10_000L\n}\nbuilder.setMaxUpdateAgeMillis(maxUpdateAgeMillis);","typeGuard":"static boolean isValidAge(long v) { return v > 0; }","tryCatchPattern":"try { builder.setMaxUpdateAgeMillis(age); } catch (IllegalArgumentException e) { builder.setMaxUpdateAgeMillis(Long.MAX_VALUE); }","preventionTips":["Never forward raw config values that may default to 0 or -1","Clamp with Math.max(1, value) or substitute Long.MAX_VALUE for unbounded"],"tags":["location","validation","android","argument-out-of-range"],"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"}