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

RetrieveBytesRequest validates each key in the provided list; null or empty-string elements cause an IllegalArgumentException. The valid keys are copied into an unmodifiable internal list, so bad entries fail before construction completes.

Source

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

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

    @Field(value = 2, getterName = "getRetrieveAll")
    private final boolean retrieveAll;

    @Constructor
    RetrieveBytesRequest(@Param(1) List<String> keys, @Param(2) boolean retrieveAll) {
        if (retrieveAll && keys != null && !keys.isEmpty()) {
            throw new IllegalArgumentException("retrieveAll was set to true but other constraint(s) was also provided: keys");
        }
        this.retrieveAll = retrieveAll;

        List<String> tmp = new ArrayList<>();
        if (keys != null) {
            for (String k : keys) {
                if (k == null || k.isEmpty()) {
                    throw new IllegalArgumentException("Element in keys cannot be null or empty");
                }
                tmp.add(k);
            }
        }
        this.keys = Collections.unmodifiableList(tmp);
    }

    /**
     * Returns the list of keys whose associated data, if any, should be retrieved.
     * <p>
     * An empty list means that no key-based filtering will be performed. In other words, no data will be returned 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 requested with the default key
     * {@link BlockstoreClient#DEFAULT_BYTES_DATA_KEY}.
     */
    public List<String> getKeys() {
        return keys;

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Sanitize the list: filter out null and empty strings before building the request.
  2. Assert/log unexpected blank keys at the source to catch data-quality issues early.
  3. After filtering, check the list is non-empty before making the retrieval call.

Example fix

// before
RetrieveBytesRequest req = RetrieveBytesRequest.builder().addAllKeys(maybeDirtyKeys).build();
// after
List<String> clean = new ArrayList<>();
for (String k : maybeDirtyKeys) if (k != null && !k.isEmpty()) clean.add(k);
RetrieveBytesRequest req = RetrieveBytesRequest.builder().addAllKeys(clean).build();
Defensive patterns

Strategy: validation

Validate before calling

for (String k : keys) { if (k == null || k.isEmpty()) throw new IllegalArgumentException("keys must be non-null, non-empty"); }

Type guard

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

Try / catch

try { req = builder.build(); } catch (IllegalArgumentException e) { log.warn("Invalid key entry", e); }

Prevention

When it happens

Trigger: Constructing RetrieveBytesRequest (directly or via builder) where the keys list contains a null or "" element.

Common situations: Keys sourced from SharedPreferences, server responses, or collections that may include null/blank entries and are passed through unfiltered.

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/d139392df94500f4. Report an issue: GitHub.