java-native-access/jna · error · IllegalArgumentException

Unsupported argument type <argClassName> at parameter <index

Error message

Unsupported argument type <argClassName> at parameter <index> of function <name>

What it means

JNA throws this IllegalArgumentException in Function.convertArgument when an argument passed to a native function call is of a Java type that JNA cannot map to a native type (and is not an array case or an allowed plain Object). JNA only supports a fixed set of mappings (primitives, Pointer, Structure, Callback, String, WString, Buffer, IntegerType, etc.).

Source

Thrown at src/com/sun/jna/Function.java:629

                    pointers[i] = ss[i] != null ? ss[i].getPointer() : null;
                }
                return new PointerArray(pointers);
            } else if (ss.length == 0) {
                throw new IllegalArgumentException("Structure array must have non-zero length");
            } else if (ss[0] == null) {
                Structure.newInstance((Class<? extends Structure>) type).toArray(ss);
                return ss[0].getPointer();
            } else {
                Structure.autoWrite(ss);
                return ss[0].getPointer();
            }
        } else if (argClass.isArray()){
            throw new IllegalArgumentException("Unsupported array argument type: "
                                               + argClass.getComponentType());
        } else if (allowObjects) {
            return arg;
        } else if (!Native.isSupportedNativeType(arg.getClass())) {
            throw new IllegalArgumentException("Unsupported argument type "
                                               + arg.getClass().getName()
                                               + " at parameter " + index
                                               + " of function " + getName());
        }
        return arg;
    }

    private boolean isPrimitiveArray(Class<?> argClass) {
        return argClass.isArray()
            && argClass.getComponentType().isPrimitive();
    }

    /**
     * Call the native function being represented by this object
     *
     * @param args Arguments to pass to the native function
     */
    public void invoke(Object[] args) {

View on GitHub (pinned to d036ad9781)

Solutions

  1. Change the parameter type to a JNA-mappable type (String, Pointer, Structure, Callback, IntegerType, primitive, array of those).
  2. Wrap the object: subclass PointerType or Structure and pass that.
  3. For Windows WString APIs, ensure appropriate options so String maps correctly; otherwise convert explicitly.
  4. If you truly need pass-through, use Pointer or pass the object through a Structure field of type Pointer.

Example fix

// before
int process(Object obj);
// after
int process(MyStruct struct); // MyStruct extends Structure
Defensive patterns

Strategy: type-guard

Validate before calling

static boolean isJnaMappable(Object o) {
  return o == null || o instanceof Boolean || o instanceof Byte || o instanceof Short
      || o instanceof Character || o instanceof Integer || o instanceof Long || o instanceof Float
      || o instanceof Double || o instanceof String || o instanceof WString || o instanceof Buffer
      || o instanceof Pointer || o instanceof Structure || o instanceof Callback
      || (o != null && o.getClass().isArray());
}

Type guard

static <T> T requireMappable(T arg) {
  if (!isJnaMappable(arg)) throw new IllegalArgumentException("Not JNA-mappable: " + arg.getClass());
  return arg;
}

Try / catch

try {
  lib.fn(arg);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Unsupported argument type")) {
    throw new IllegalStateException("Convert arg to Pointer/Structure/String before native call", e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling a method on a Library interface (via Function.invoke -> convertArgument) with a parameter of an unmapped type, e.g. a POJO, BigDecimal, List, or custom class not extending PointerType/IntegerType and not a Structure/Callback.

Common situations: Passing Java collection or wrapper objects as native arguments; passing a String where a Structure is required; using java.lang.Object parameters without W32APIOptions/allowObjects; refactoring an interface signature to a non-mappable type after a JNA upgrade.

Related errors


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