{"record":{"id":"87a153ad57bf2bd9","repo":"microg/GmsCore","slug":"no-geofence-has-been-added-to-this-request","errorCode":null,"errorMessage":"No geofence has been added to this request.","messagePattern":"No geofence has been added to this request\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-location/src/main/java/com/google/android/gms/location/GeofencingRequest.java","lineNumber":148,"sourceCode":"         *\n         * @param initialTrigger the notification behavior. It's a bit-wise of {@link GeofencingRequest#INITIAL_TRIGGER_ENTER} and/or\n         *                       {@link GeofencingRequest#INITIAL_TRIGGER_EXIT} and/or {@link GeofencingRequest#INITIAL_TRIGGER_DWELL}. When\n         *                       {@code initialTrigger} is set to 0 ({@code setInitialTrigger(0)}), initial trigger would be disabled.\n         * @return the builder object itself for method chaining\n         */\n        public GeofencingRequest.Builder setInitialTrigger(@InitialTrigger int initialTrigger) {\n            this.initialTrigger = initialTrigger;\n            return this;\n        }\n\n        /**\n         * Builds the {@link GeofencingRequest} object.\n         *\n         * @return a {@link GeofencingRequest} object\n         * @throws IllegalArgumentException if no geofence has been added to this list\n         */\n        public GeofencingRequest build() {\n            if (geofences.isEmpty()) throw new IllegalArgumentException(\"No geofence has been added to this request.\");\n            GeofencingRequest request = new GeofencingRequest();\n            request.geofences = geofences;\n            request.initialTrigger = initialTrigger;\n            return request;\n        }\n    }\n\n    @NonNull\n    @Override\n    public String toString() {\n        return \"GeofencingRequest[geofences=\" + this.geofences + \", initialTrigger=\" + this.initialTrigger + \", tag=\" + this.tag + \", attributionTag=\" + this.contextAttributionTag + \"]\";\n    }\n\n    public static final Creator<GeofencingRequest> CREATOR = new AutoCreator<>(GeofencingRequest.class);\n}\n","sourceCodeStart":130,"sourceCodeEnd":164,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/src/main/java/com/google/android/gms/location/GeofencingRequest.java#L130-L164","documentation":"GeofencingRequest.Builder.build() throws IllegalArgumentException when no geofence was added via addGeofence()/addGeofences() before building. The initial trigger may be 0, but at least one geofence is mandatory.","triggerScenarios":"Calling build() without any successful addGeofence()/addGeofences() call, or after all addGeofence calls were skipped due to null/type errors upstream.","commonSituations":"Dynamically assembling fences from user data where all entries were filtered out; exception during addGeofence silently caught, leaving the builder empty; calling build() in a code path that assumed fences existed.","solutions":["Ensure at least one addGeofence() succeeds before calling build()","Check the fence collection size and skip registration (or surface a user error) when empty","Fix upstream null/type errors that prevented geofences from being added"],"exampleFix":"// before\nGeofencingRequest request = new GeofencingRequest.Builder().build(); // throws if empty\n// after\nif (fenceList.isEmpty()) {\n    return; // nothing to register\n}\nGeofencingRequest.Builder rb = new GeofencingRequest.Builder();\nfor (Geofence f : fenceList) rb.addGeofence(f);\nGeofencingRequest request = rb.build();","handlingStrategy":"validation","validationCode":"if (fenceCount == 0) { Log.w(TAG, \"No geofences to register\"); return; }\nGeofencingRequest request = builder.build();","typeGuard":null,"tryCatchPattern":"try { return builder.build(); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"No geofence\")) { return null; // or signal empty request upstream } throw e; }","preventionTips":["Verify the geofence list is non-empty before creating the builder","Check that addGeofence exceptions weren't silently swallowed, leaving the builder empty"],"tags":["geofencing","validation","android","empty-collection"],"backgroundTag":"empty-required-field","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"}