{"record":{"id":"7dc36df3ba076923","repo":"java-native-access/jna","slug":"errno-native-getlasterror","errorCode":null,"errorMessage":"errno: \" + Native.getLastError()","messagePattern":"errno: \" \\+ Native\\.getLastError\\(\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/bsd/ExtAttrUtil.java","lineNumber":44,"sourceCode":"import static java.util.Collections.*;\n\nimport java.io.IOException;\nimport java.io.UnsupportedEncodingException;\nimport java.nio.ByteBuffer;\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport com.sun.jna.Native;\nimport com.sun.jna.platform.unix.LibCAPI.size_t;\n\npublic class ExtAttrUtil {\n\n    public static List<String> list(String path) throws IOException {\n        // get required buffer size\n        long bufferLength = ExtAttr.INSTANCE.extattr_list_file(path, ExtAttr.EXTATTR_NAMESPACE_USER, null, new size_t(0)).longValue();\n\n        if (bufferLength < 0) {\n            throw new IOException(\"errno: \" + Native.getLastError());\n        }\n\n        if (bufferLength == 0) {\n            return emptyList();\n        }\n\n        ByteBuffer buffer = ByteBuffer.allocate((int) bufferLength);\n        long valueLength = ExtAttr.INSTANCE.extattr_list_file(path, ExtAttr.EXTATTR_NAMESPACE_USER, buffer, new size_t(bufferLength)).longValue();\n\n        if (valueLength < 0) {\n            throw new IOException(\"errno: \" + Native.getLastError());\n        }\n\n        return decodeStringList(buffer);\n    }\n\n    public static ByteBuffer get(String path, String name) throws IOException {\n        // get required buffer size","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/bsd/ExtAttrUtil.java#L26-L62","documentation":"Generic errno sentinel thrown by the ExtAttr helpers when the FreeBSD extattr_syscall(2) call (list/get/set) returns -1. The real cause is in the appended errno value — e.g. ENOATTR (attribute not found), ENOENT (bad path), EPERM/EACCES (not owner or no permission on the filesystem), or ENOTSUP (filesystem without extended attributes, e.g. UFS without ACL support).","triggerScenarios":"Thrown at contrib/platform/src/com/sun/jna/platform/bsd/ExtAttrUtil.java:44 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the errno in the message and map it: 2 = ENOENT (check path), 87/ENOATTR = missing attribute, 13 = EACCES (permissions)","Verify the filesystem supports extended attributes and the process owns the file or runs with privileges","Use l* variants / correct EXTATTR namespace if the attribute lives in a different namespace"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}