microg/GmsCore · error · IllegalArgumentException
No geofence has been added to this request.
Error message
No geofence has been added to this request.
What it means
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.
Source
Thrown at play-services-location/src/main/java/com/google/android/gms/location/GeofencingRequest.java:148
*
* @param initialTrigger the notification behavior. It's a bit-wise of {@link GeofencingRequest#INITIAL_TRIGGER_ENTER} and/or
* {@link GeofencingRequest#INITIAL_TRIGGER_EXIT} and/or {@link GeofencingRequest#INITIAL_TRIGGER_DWELL}. When
* {@code initialTrigger} is set to 0 ({@code setInitialTrigger(0)}), initial trigger would be disabled.
* @return the builder object itself for method chaining
*/
public GeofencingRequest.Builder setInitialTrigger(@InitialTrigger int initialTrigger) {
this.initialTrigger = initialTrigger;
return this;
}
/**
* Builds the {@link GeofencingRequest} object.
*
* @return a {@link GeofencingRequest} object
* @throws IllegalArgumentException if no geofence has been added to this list
*/
public GeofencingRequest build() {
if (geofences.isEmpty()) throw new IllegalArgumentException("No geofence has been added to this request.");
GeofencingRequest request = new GeofencingRequest();
request.geofences = geofences;
request.initialTrigger = initialTrigger;
return request;
}
}
@NonNull
@Override
public String toString() {
return "GeofencingRequest[geofences=" + this.geofences + ", initialTrigger=" + this.initialTrigger + ", tag=" + this.tag + ", attributionTag=" + this.contextAttributionTag + "]";
}
public static final Creator<GeofencingRequest> CREATOR = new AutoCreator<>(GeofencingRequest.class);
}
View on GitHub (pinned to 157c9d86ac)
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
Example fix
// before
GeofencingRequest request = new GeofencingRequest.Builder().build(); // throws if empty
// after
if (fenceList.isEmpty()) {
return; // nothing to register
}
GeofencingRequest.Builder rb = new GeofencingRequest.Builder();
for (Geofence f : fenceList) rb.addGeofence(f);
GeofencingRequest request = rb.build(); Defensive patterns
Strategy: validation
Validate before calling
if (fenceCount == 0) { Log.w(TAG, "No geofences to register"); return; }
GeofencingRequest request = builder.build(); Try / catch
try { return builder.build(); } catch (IllegalArgumentException e) { if (e.getMessage().contains("No geofence")) { return null; // or signal empty request upstream } throw e; } Prevention
- Verify the geofence list is non-empty before creating the builder
- Check that addGeofence exceptions weren't silently swallowed, leaving the builder empty
When it happens
Trigger: Calling build() without any successful addGeofence()/addGeofences() call, or after all addGeofence calls were skipped due to null/type errors upstream.
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- invalid radius:
- invalid latitude:
- invalid longitude:
- Transition types not set.
- Non-negative loitering delay needs to be set when transition
AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06).
Data as JSON: /api/errors/87a153ad57bf2bd9.
Report an issue: GitHub.