{"record":{"id":"d6042e54cdcc73d0","repo":"microg/GmsCore","slug":"geofence-region-not-set","errorCode":null,"errorMessage":"Geofence region not set.","messagePattern":"Geofence region not set\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-location/src/main/java/com/google/android/gms/location/Geofence.java","lineNumber":120,"sourceCode":"        private String requestId;\n        private @TransitionTypes int transitionTypes;\n\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;","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/src/main/java/com/google/android/gms/location/Geofence.java#L102-L138","documentation":"build() checks that a circular region was configured: regionType is -1 until setCircularRegion(latitude, longitude, radius) is called. Without a region there is nothing to monitor, so the builder throws IllegalArgumentException.","triggerScenarios":"Calling build() without calling setCircularRegion(double, double, float) on the builder.","commonSituations":"Forgetting the region when assembling a long builder chain; passing NaN/placeholder values elsewhere and skipping the region call; dynamic fence construction where the coordinates branch is skipped.","solutions":["Call setCircularRegion(latitude, longitude, radiusInMeters) before build()","Ensure the radius is a positive finite value and coordinates are valid"],"exampleFix":"// before\nGeofence fence = new Geofence.Builder()\n    .setRequestId(\"fence1\")\n    .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)\n    .setExpirationDuration(3600000)\n    .build(); // throws\n// after\nGeofence fence = new Geofence.Builder()\n    .setRequestId(\"fence1\")\n    .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)\n    .setExpirationDuration(3600000)\n    .setCircularRegion(37.4219, -122.0840, 100f)\n    .build();","handlingStrategy":"validation","validationCode":"if (Double.isNaN(lat) || Double.isNaN(lng) || radius <= 0) {\n    throw new IllegalStateException(\"Valid circular region required before build()\");\n}","typeGuard":null,"tryCatchPattern":"try { return builder.build(); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"region\")) { throw new IllegalArgumentException(\"Geofence requires setCircularRegion(lat, lng, radius)\", e); } throw e; }","preventionTips":["Call setCircularRegion() with validated coordinates and a positive radius","Guard against NaN coordinates coming from GPS/network sources before building"],"tags":["geofencing","validation","android","region"],"backgroundTag":"missing-required-argument","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"}