{"record":{"id":"2ef55aaeb4be7160","repo":"oracle/graal","slug":"set-not-supported","errorCode":null,"errorMessage":"set() not supported.","messagePattern":"set\\(\\) not supported\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"info","filePath":"espresso-compiler-stub/src/com.oracle.truffle.espresso.vmaccess/src/com/oracle/truffle/espresso/vmaccess/EspressoExternalHostProxies.java","lineNumber":369,"sourceCode":"                return map.get(key);\n            }\n\n            @Override\n            public Object getMemberKeys() {\n                Object[] keys = map.keySet().toArray();\n                return new ProxyArray() {\n                    @Override\n                    public Object get(long index) {\n                        try {\n                            return keys[Math.toIntExact(index)];\n                        } catch (ArithmeticException e) {\n                            throw new ArrayIndexOutOfBoundsException(\"Index should be an int\");\n                        }\n                    }\n\n                    @Override\n                    public void set(long index, Value value) {\n                        throw new UnsupportedOperationException(\"set() not supported.\");\n                    }\n\n                    @Override\n                    public long getSize() {\n                        return keys.length;\n                    }\n                };\n            }\n\n            @Override\n            public boolean hasMember(String key) {\n                return map.containsKey(key);\n            }\n\n            @Override\n            public void putMember(String key, Value value) {\n                throw new UnsupportedOperationException(\"putMember() not supported.\");\n            }","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/espresso-compiler-stub/src/com.oracle.truffle.espresso.vmaccess/src/com/oracle/truffle/espresso/vmaccess/EspressoExternalHostProxies.java#L351-L387","documentation":"UnsupportedOperationException from the read-only ProxyArray that EspressoExternalHostProxies.getMemberKeys builds over the host object's member-key map. The array is a derived view (keys of an immutable Map.copyOf map of methods); mutating it has no meaningful semantics — writes would not propagate back to the host class — so set() deliberately throws.","triggerScenarios":"Guest language code calling the array 'put/store' operation (e.g. JS arr[0] = x) on the member-keys mirror obtained from a host object exposed via the external host proxy.","commonSituations":"Guest scripts treating every interop array as mutable; generic polyglot tooling (REPLs, debuggers) that attempts writes during exploration; copying guest code from a mutable Java array mirror to a host object's key view.","solutions":["Do not write to the member-keys view; it reflects the host object's method set, which is fixed by the class.","If guest code needs a mutable array, copy the keys into a guest-native array first (e.g. JS [...keys]).","Catch/handle UnsupportedOperationException in the guest interop layer and surface 'read-only' to the script author.","Verify you are not confusing getMemberKeys() (read-only metadata) with an actual data array returned by a member call."],"exampleFix":"// before (guest JS)\nhostObj.memberKeys[0] = 'x'; // UnsupportedOperationException\n\n// after (guest JS)\nconst keys = [...hostObj.memberKeys]; // copy into guest array\nkeys[0] = 'x'; // mutation on the copy only","handlingStrategy":"validation","validationCode":"// interop caller: check writability metadata before write\nif (memberKeys.isMemberWritable() /* or Member.isWritable for arrays */) {\n    memberKeys.setElement(idx, v);\n} else {\n    throw new UnsupportedOperationException(\"member keys are a read-only view\");\n}","typeGuard":null,"tryCatchPattern":"try { arr.set(idx, value); } catch (UnsupportedOperationException e) { /* read-only key view: copy into guest array instead */ }","preventionTips":["Treat member-key mirrors as metadata; copy them into guest-native arrays when mutability is needed.","Check the interop 'writable/insertable' metadata before attempting writes.","Surface read-only violations to script authors instead of retrying the write."],"tags":["polyglot","truffle","proxy-array","read-only","unsupported-operation"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}