{"record":{"id":"9e8733c3c990d55c","repo":"elastic/elasticsearch","slug":"attempting-to-address-a-non-array-type-receivercl","errorCode":null,"errorMessage":"Attempting to address a non-array type [receiverClass] as an array.","messagePattern":"Attempting to address a non-array type \\[receiverClass\\] as an array\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java","lineNumber":753,"sourceCode":"        );\n    }\n\n    /**\n     * Returns a method handle to do an array store.\n     * @param receiverClass Class of the array to store the value in\n     * @return a MethodHandle that accepts the receiver as first argument, the index as second argument,\n     *   and the value to set as 3rd argument. Return value is undefined and should be ignored.\n     */\n    static MethodHandle lookupArrayStore(Class<?> receiverClass) {\n        if (receiverClass.isArray()) {\n            return MethodHandles.arrayElementSetter(receiverClass);\n        } else if (Map.class.isAssignableFrom(receiverClass)) {\n            // maps allow access like mymap[key]\n            return MAP_PUT;\n        } else if (List.class.isAssignableFrom(receiverClass)) {\n            return LIST_SET;\n        }\n        throw new IllegalArgumentException(\n            \"Attempting to address a non-array type \" + \"[\" + receiverClass.getCanonicalName() + \"] as an array.\"\n        );\n    }\n\n    /**\n     * Returns a method handle to do an array load.\n     * @param receiverClass Class of the array to load the value from\n     * @return a MethodHandle that accepts the receiver as first argument, the index as second argument.\n     *   It returns the loaded value.\n     */\n    static MethodHandle lookupArrayLoad(Class<?> receiverClass) {\n        if (receiverClass.isArray()) {\n            return MethodHandles.arrayElementGetter(receiverClass);\n        } else if (Map.class.isAssignableFrom(receiverClass)) {\n            // maps allow access like mymap[key]\n            return MAP_GET;\n        } else if (List.class.isAssignableFrom(receiverClass)) {\n            return LIST_GET;","sourceCodeStart":735,"sourceCodeEnd":771,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java#L735-L771","documentation":"Def.lookupArrayStore returns the array-store handle for bracket assignment x[i] = v. It handles arrays (arrayElementSetter), Maps (MAP_PUT), and Lists (LIST_SET). For any other receiverClass it throws 'Attempting to address a non-array type [...] as an array'. This is the store-side counterpart to lookupIndexNormalize/lookupArrayLoad and fires when the receiver cannot receive a bracket-store at all.","triggerScenarios":"A Painless script writes x[i] = value where x is a 'def' whose runtime class is not an array, Map, or List — e.g. assigning into a String, a number, or a scalar wrapper.","commonSituations":"Treating a scalar as a container. Receiver resolved to an immutable type. Mistaking a wrapper for a collection. Trying to mutate doc values via bracket assignment.","solutions":["Confirm the receiver is a mutable array, List, or Map before bracket assignment.","Use a List/Map from params or ctx for accumulation, not scalar variables.","Type the receiver concretely to get compile-time validation.","For source updates in update-by-query, write to ctx._source (a Map) instead of doc fields."],"exampleFix":"// before\ndef n = 5;\nn[0] = 1; // scalar is not array-storable\n// after\ndef arr = new int[1];\narr[0] = 1;","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Before bracket-assign on a def value, confirm it is a mutable array/List/Map\nfunction isMutableContainer(v) {\n  return Array.isArray(v) || v instanceof Map || (v && typeof v.length === 'number');\n}\n// if (!isMutableContainer(x)) throw new Error('Cannot store into non-container');","tryCatchPattern":"// On 'Attempting to address a non-array type', tell the author the receiver is a scalar/immutable and to use a List/Map/ctx._source.","preventionTips":["Allocate a List/array/Map for accumulation; don't assign into scalars.","For source updates, write to ctx._source, not doc fields.","Static-type mutable buffers to catch errors at compile time."],"tags":["painless","script","dynamic-dispatch","def","indexing","array-store","runtime"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}