{"record":{"id":"171c9675d3a7d351","repo":"microg/GmsCore","slug":"notification-responsiveness-should-be-nonnegative","errorCode":null,"errorMessage":"Notification responsiveness should be nonnegative.","messagePattern":"Notification responsiveness should be nonnegative\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-location/src/main/java/com/google/android/gms/location/Geofence.java","lineNumber":122,"sourceCode":"\n        /**\n         * Creates a geofence object.\n         *\n         * @throws IllegalArgumentException if any parameters are not set or out of range\n         */\n        public Geofence build() throws IllegalArgumentException {\n            if (requestId == null) {\n                throw new IllegalArgumentException(\"Request ID not set.\");\n            } else if (transitionTypes == 0) {\n                throw new IllegalArgumentException(\"Transition types not set.\");\n            } else if ((transitionTypes & GEOFENCE_TRANSITION_DWELL) > 0 && loiteringDelay < 0) {\n                throw new IllegalArgumentException(\"Non-negative loitering delay needs to be set when transition types include GEOFENCE_TRANSITION_DWELLING.\");\n            } else if (expirationTime == Long.MIN_VALUE) {\n                throw new IllegalArgumentException(\"Expiration not set.\");\n            } else if (regionType == -1) {\n                throw new IllegalArgumentException(\"Geofence region not set.\");\n            } else if (notificationResponsiveness < 0) {\n                throw new IllegalArgumentException(\"Notification responsiveness should be nonnegative.\");\n            } else {\n                return new ParcelableGeofence(requestId, expirationTime, regionType, latitude, longitude, radius, transitionTypes, notificationResponsiveness, loiteringDelay);\n            }\n        }\n\n        /**\n         * Sets the region of this geofence. The geofence represents a circular area on a flat, horizontal plane.\n         *\n         * @param latitude  latitude in degrees, between -90 and +90 inclusive\n         * @param longitude longitude in degrees, between -180 and +180 inclusive\n         * @param radius    radius in meters\n         */\n        public Builder setCircularRegion(@FloatRange(from = -90.0d, to = 90.0d) double latitude, @FloatRange(from = -180.0d, to = 180.0d) double longitude, @FloatRange(from = 0.0d, fromInclusive = false) float radius) {\n            this.regionType = 1;\n            this.latitude = latitude;\n            this.longitude = longitude;\n            this.radius = radius;\n            return this;","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/src/main/java/com/google/android/gms/location/Geofence.java#L104-L140","documentation":"notificationResponsiveness defaults to -1/invalid negative in this builder; build() requires it to be nonnegative because it controls how often the system checks for geofence transitions. A negative value is meaningless, so IllegalArgumentException is thrown.","triggerScenarios":"Calling build() after calling setNotificationResponsiveness(int) with a negative value (the field must be >= 0; 0 means use the default).","commonSituations":"Passing an uninitialized or computed-negative value (e.g. from a config defaulting to -1); misunderstanding that 0 is allowed while -1 is not.","solutions":["Call setNotificationResponsiveness() with a nonnegative millisecond value (e.g. 30000), or omit the call entirely to use the default","Clamp or validate any dynamically computed responsiveness value before passing it"],"exampleFix":"// before\nint responsiveness = config.getInt(\"responsiveness\", -1);\nbuilder.setNotificationResponsiveness(responsiveness);\nGeofence fence = builder.build(); // throws\n// after\nint responsiveness = Math.max(0, config.getInt(\"responsiveness\", 0));\nbuilder.setNotificationResponsiveness(responsiveness);\nGeofence fence = builder.build();","handlingStrategy":"validation","validationCode":"if (responsivenessMillis < 0) responsivenessMillis = 0; // 0 = default","typeGuard":"static boolean isValidResponsiveness(long v) { return v >= 0; }","tryCatchPattern":"try { return builder.build(); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"responsiveness\")) { builder.setNotificationResponsiveness(0); return builder.build(); } throw e; }","preventionTips":["Never pass config defaults of -1 to setNotificationResponsiveness; use 0 to mean default","Clamp computed values with Math.max(0, value)"],"tags":["geofencing","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-14T00:17:10.932Z"}