{"record":{"id":"d139392df94500f4","repo":"microg/GmsCore","slug":"element-in-keys-cannot-be-null-or-empty-d13939","errorCode":null,"errorMessage":"Element in keys cannot be null or empty","messagePattern":"Element in keys cannot be null or empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-auth-blockstore/src/main/java/com/google/android/gms/auth/blockstore/RetrieveBytesRequest.java","lineNumber":49,"sourceCode":"\n    @Field(value = 1, getterName = \"getKeys\")\n    private final List<String> keys;\n\n    @Field(value = 2, getterName = \"getRetrieveAll\")\n    private final boolean retrieveAll;\n\n    @Constructor\n    RetrieveBytesRequest(@Param(1) List<String> keys, @Param(2) boolean retrieveAll) {\n        if (retrieveAll && keys != null && !keys.isEmpty()) {\n            throw new IllegalArgumentException(\"retrieveAll was set to true but other constraint(s) was also provided: keys\");\n        }\n        this.retrieveAll = retrieveAll;\n\n        List<String> tmp = new ArrayList<>();\n        if (keys != null) {\n            for (String k : keys) {\n                if (k == null || k.isEmpty()) {\n                    throw new IllegalArgumentException(\"Element in keys cannot be null or empty\");\n                }\n                tmp.add(k);\n            }\n        }\n        this.keys = Collections.unmodifiableList(tmp);\n    }\n\n    /**\n     * Returns the list of keys whose associated data, if any, should be retrieved.\n     * <p>\n     * 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\n     * other criterion is provided.\n     * <p>\n     * Note that the app data that was stored without an explicit key can be requested with the default key\n     * {@link BlockstoreClient#DEFAULT_BYTES_DATA_KEY}.\n     */\n    public List<String> getKeys() {\n        return keys;","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-auth-blockstore/src/main/java/com/google/android/gms/auth/blockstore/RetrieveBytesRequest.java#L31-L67","documentation":"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.","triggerScenarios":"Constructing RetrieveBytesRequest (directly or via builder) where the keys list contains a null or \"\" element.","commonSituations":"Keys sourced from SharedPreferences, server responses, or collections that may include null/blank entries and are passed through unfiltered.","solutions":["Sanitize the list: filter out null and empty strings before building the request.","Assert/log unexpected blank keys at the source to catch data-quality issues early.","After filtering, check the list is non-empty before making the retrieval call."],"exampleFix":"// before\nRetrieveBytesRequest req = RetrieveBytesRequest.builder().addAllKeys(maybeDirtyKeys).build();\n// after\nList<String> clean = new ArrayList<>();\nfor (String k : maybeDirtyKeys) if (k != null && !k.isEmpty()) clean.add(k);\nRetrieveBytesRequest req = RetrieveBytesRequest.builder().addAllKeys(clean).build();","handlingStrategy":"validation","validationCode":"for (String k : keys) { if (k == null || k.isEmpty()) throw new IllegalArgumentException(\"keys must be non-null, non-empty\"); }","typeGuard":"boolean isValidKey(String k) { return k != null && !k.isEmpty(); }","tryCatchPattern":"try { req = builder.build(); } catch (IllegalArgumentException e) { log.warn(\"Invalid key entry\", e); }","preventionTips":["Filter null/empty entries when collecting keys from external sources.","Keep keys in a Set<String> to avoid duplicates and ease null-checking.","Validate at data-ingestion time, not at request-build time."],"tags":["android","blockstore","validation","illegal-argument"],"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"}