{"record":{"id":"97b7b617e58c7862","repo":"oracle/graal","slug":"is-unknown-or-read-only-attribute","errorCode":null,"errorMessage":"'{}' is unknown or read-only attribute","messagePattern":"'(.+?)' is unknown or read-only attribute","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"espresso/src/com.oracle.truffle.espresso.io/src/sun/nio/fs/TruffleBasicFileAttributeView.java","lineNumber":101,"sourceCode":"        return map;\n    }\n\n    void setAttribute(String attribute, Object value)\n                    throws IOException {\n        try {\n            switch (attribute) {\n                case \"lastModifiedTime\":\n                    setTimes((FileTime) value, null, null);\n                    break;\n                case \"lastAccessTime\":\n                    setTimes(null, (FileTime) value, null);\n                    break;\n                case \"creationTime\":\n                    setTimes(null, null, (FileTime) value);\n                    break;\n            }\n        } catch (IllegalArgumentException x) {\n            throw new UnsupportedOperationException(\"'\" + attribute +\n                            \"' is unknown or read-only attribute\");\n        }\n    }\n\n    // region native methods\n\n    private static native TruffleBasicFileAttributes readAttributes0(TrufflePath path, boolean followLinks) throws IOException;\n\n    /*\n     * Updates any or all of the file's last modified time, last access time, and create time\n     * attributes. This method updates the file's timestamp attributes. -1 values are ignored e.g.\n     * not set.\n     */\n    private static native void setTimes0(TrufflePath path, boolean followLinks, long lastModifiedTimeMillis, long lastAccessTimeMillis, long createTimeMillis) throws IOException;\n\n    // endregion native methods\n}\n","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/espresso/src/com.oracle.truffle.espresso.io/src/sun/nio/fs/TruffleBasicFileAttributeView.java#L83-L119","documentation":"TruffleBasicFileAttributeView.setAttribute dispatches on the attribute name for lastModifiedTime/lastAccessTime/creationTime; if the switch falls through (unknown name) or setTimes throws IllegalArgumentException (bad value), it is converted to UnsupportedOperationException(\"'<attr>' is unknown or read-only attribute\"). The view only supports the three basic timestamps.","triggerScenarios":"Guest code calling Files.setAttribute(path, \"basic:isDirectory\", ...) or setting unsupported/read-only attributes (isRegularFile, isSymbolicLink, fileKey) through the Truffle filesystem provider; passing a non-FileTime to a time attribute.","commonSituations":"Generic metadata-copying utilities that iterate attributes and try to set each one; code assuming all attributes read via readAttributes can be written back.","solutions":["Only set 'basic:lastModifiedTime', 'basic:lastAccessTime', 'basic:creationTime' with FileTime values.","Filter out read-only attributes (size, isDirectory, fileKey, ...) before writing.","Use the typed API: Files.setLastModifiedTime(path, time) instead of string-based setAttribute."],"exampleFix":"// before\nFiles.setAttribute(p, \"basic:isDirectory\", false); // read-only -> throws\n\n// after\nFiles.setLastModifiedTime(p, FileTime.fromMillis(System.currentTimeMillis()));","handlingStrategy":"validation","validationCode":"static final Set<String> WRITABLE = Set.of(\"basic:lastModifiedTime\", \"basic:lastAccessTime\", \"basic:creationTime\");\nif (WRITABLE.contains(attr) && value instanceof FileTime) { Files.setAttribute(p, attr, value); }","typeGuard":null,"tryCatchPattern":"try {\n    Files.setAttribute(p, attr, value);\n} catch (UnsupportedOperationException e) {\n    if (e.getMessage().contains(\"unknown or read-only attribute\")) { /* skip read-only attr */ }\n}","preventionTips":["Filter attribute maps to the three basic timestamps before writing.","Use Files.setLastModifiedTime instead of string-based setAttribute."],"tags":["espresso","nio","file-attributes","unsupported-operation"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}