microg/GmsCore · error · IllegalArgumentException

Element in keys cannot be null or empty

Error message

Element in keys cannot be null or empty

What it means

DeleteBytesRequest validates every entry of the keys list: any null or empty-string element is rejected with IllegalArgumentException. The keys parameter cannot be null here because the deleteAll check above guarantees keys is non-null when iterating.

Source

Thrown at play-services-auth-blockstore/src/main/java/com/google/android/gms/auth/blockstore/DeleteBytesRequest.java:47

@SafeParcelable.Class
public class DeleteBytesRequest extends AbstractSafeParcelable {

    @Field(value = 1, getterName = "getKeys")
    private final List<String> keys;

    @Field(value = 2, getterName = "getDeleteAll")
    private final boolean deleteAll;

    @Constructor
    DeleteBytesRequest(@Param(1) List<String> keys, @Param(2) boolean deleteAll) {
        this.keys = keys;
        this.deleteAll = deleteAll;
        if (deleteAll && keys != null && !keys.isEmpty()) {
            throw new IllegalArgumentException("deleteAll was set to true but keys were also provided");
        }
        for (String key : keys) {
            if (key == null || key.isEmpty()) {
                throw new IllegalArgumentException("Element in keys cannot be null or empty");
            }
        }
    }

    /**
     * Returns the list of keys whose associated data, if any, should be deleted.
     * <p>
     * An empty list means that no key-based filtering will be performed. In other words, no data will be deleted if the key list is empty and no other
     * criterion is provided.
     * <p>
     * Note that the app data that was stored without an explicit key can be deleted with the default key
     * {@link BlockstoreClient#DEFAULT_BYTES_DATA_KEY}.
     */
    @NonNull
    public List<String> getKeys() {
        return keys;
    }

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Filter the list before constructing: remove null and empty strings from the keys collection.
  2. If a null/empty entry means 'no key', skip it instead of adding it to the list.
  3. If the resulting list is empty after filtering, decide whether the request is still meaningful before calling the API.

Example fix

// before
List<String> keys = rawKeys; // may contain nulls/""
DeleteBytesRequest req = new DeleteBytesRequest(keys, false);
// after
List<String> keys = rawKeys.stream().filter(k -> k != null && !k.isEmpty()).collect(Collectors.toList());
DeleteBytesRequest req = new DeleteBytesRequest(keys, false);
Defensive patterns

Strategy: validation

Validate before calling

List<String> clean = keys == null ? Collections.emptyList() : keys.stream().filter(k -> k != null && !k.isEmpty()).collect(Collectors.toList());
if (clean.isEmpty()) return; // nothing to delete

Type guard

boolean isValidKey(String k) { return k != null && !k.isEmpty(); }

Try / catch

try { request = new DeleteBytesRequest(keys, false); } catch (IllegalArgumentException e) { log.warn("Bad keys list", e); }

Prevention

When it happens

Trigger: Constructing DeleteBytesRequest (directly or via builder) with a keys list that contains a null element or a "" (empty string) element.

Common situations: Populating keys from dynamic sources such as user input, a database cursor, or a collection that may contain nulls/empty strings without filtering them out first.

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


AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06). Data as JSON: /api/errors/2f85b82231194dd1. Report an issue: GitHub.