java-native-access/jna · error · IOException

errno: " + Native.getLastError()

Error message

errno: " + Native.getLastError()

What it means

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).

Source

Thrown at contrib/platform/src/com/sun/jna/platform/bsd/ExtAttrUtil.java:44

import static java.util.Collections.*;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

import com.sun.jna.Native;
import com.sun.jna.platform.unix.LibCAPI.size_t;

public class ExtAttrUtil {

    public static List<String> list(String path) throws IOException {
        // get required buffer size
        long bufferLength = ExtAttr.INSTANCE.extattr_list_file(path, ExtAttr.EXTATTR_NAMESPACE_USER, null, new size_t(0)).longValue();

        if (bufferLength < 0) {
            throw new IOException("errno: " + Native.getLastError());
        }

        if (bufferLength == 0) {
            return emptyList();
        }

        ByteBuffer buffer = ByteBuffer.allocate((int) bufferLength);
        long valueLength = ExtAttr.INSTANCE.extattr_list_file(path, ExtAttr.EXTATTR_NAMESPACE_USER, buffer, new size_t(bufferLength)).longValue();

        if (valueLength < 0) {
            throw new IOException("errno: " + Native.getLastError());
        }

        return decodeStringList(buffer);
    }

    public static ByteBuffer get(String path, String name) throws IOException {
        // get required buffer size

View on GitHub (pinned to d036ad9781)

Solutions

  1. Read the errno in the message and map it: 2 = ENOENT (check path), 87/ENOATTR = missing attribute, 13 = EACCES (permissions)
  2. Verify the filesystem supports extended attributes and the process owns the file or runs with privileges
  3. Use l* variants / correct EXTATTR namespace if the attribute lives in a different namespace
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at contrib/platform/src/com/sun/jna/platform/bsd/ExtAttrUtil.java:44 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12). Data as JSON: /api/errors/7dc36df3ba076923. Report an issue: GitHub.