{"record":{"id":"ebe2b029c65253f8","repo":"elastic/elasticsearch","slug":"key-must-not-be-null","errorCode":null,"errorMessage":"[key] must not be null","messagePattern":"\\[key\\] must not be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/adjacency/AdjacencyMatrixAggregator.java","lineNumber":62,"sourceCode":" * Aggregation for adjacency matrices.\n *\n */\npublic class AdjacencyMatrixAggregator extends BucketsAggregator {\n\n    public static final ParseField FILTERS_FIELD = new ParseField(\"filters\");\n\n    protected static class KeyedFilter implements Writeable, ToXContentFragment {\n        private final String key;\n        private final QueryBuilder filter;\n\n        public static final NamedObjectParser<KeyedFilter, String> PARSER = (\n            XContentParser p,\n            String aggName,\n            String name) -> new KeyedFilter(name, parseTopLevelQuery(p));\n\n        public KeyedFilter(String key, QueryBuilder filter) {\n            if (key == null) {\n                throw new IllegalArgumentException(\"[key] must not be null\");\n            }\n            if (filter == null) {\n                throw new IllegalArgumentException(\"[filter] must not be null\");\n            }\n            this.key = key;\n            this.filter = filter;\n        }\n\n        /**\n         * Read from a stream.\n         */\n        public KeyedFilter(StreamInput in) throws IOException {\n            key = in.readString();\n            filter = in.readNamedWriteable(QueryBuilder.class);\n        }\n\n        @Override\n        public void writeTo(StreamOutput out) throws IOException {","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/adjacency/AdjacencyMatrixAggregator.java#L44-L80","documentation":"Thrown by the KeyedFilter constructor (inside AdjacencyMatrixAggregator) when the `key` argument is null. KeyedFilter pairs a label with a query for the adjacency_matrix; a null key would corrupt the bucket-naming logic and map ordering, so it is rejected immediately.","triggerScenarios":"Constructing `new KeyedFilter(null, query)` programmatically, or submitting an adjacency_matrix request where a filter entry has a null/missing key. Reached via the PARSER when the aggregation name resolution yields null for a filter's key.","commonSituations":"REST requests where a filter object is keyed by an empty or whitespace string that downstream resolves to null. Programmatic builders using a map that permits null keys. Deserialization of malformed payloads.","solutions":["Provide a non-null, non-empty key for every filter in the adjacency_matrix.","Validate the filters map for null/empty keys before submission.","Sanitize the request body to ensure each filter object has a distinct label."],"exampleFix":"// before\nnew KeyedFilter(null, QueryBuilders.matchAllQuery());\n// after\nnew KeyedFilter(\"label\", QueryBuilders.matchAllQuery());","handlingStrategy":"validation","validationCode":"if (key == null || key.isEmpty()) {\n  throw new IllegalArgumentException(\"filter key must be non-empty\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reject null/empty keys in the filters map before constructing KeyedFilter.","Sanitize REST request bodies for missing filter labels.","Use distinct, non-null keys for every filter."],"tags":["aggregations","adjacency-matrix","null-check","validation"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}