java-native-access/jna · error · IllegalArgumentException
must be set from BOOL/BOOL[]
Error message
must be set from BOOL/BOOL[]
What it means
For EvtVarTypeBoolean, setValue only accepts a BOOL (single value, stored via intValue) or a BOOL[] (stored as an array in native memory). Any other object — Java Boolean, boolean[], int, etc. — triggers this IllegalArgumentException naming the variant type.
Source
Thrown at contrib/platform/src/com/sun/jna/platform/win32/Winevt.java:316
throw new IllegalArgumentException(type.name() + " must be set from String/String[]");
}
break;
case EvtVarTypeBoolean:
if (value.getClass().isArray() && value.getClass().getComponentType() == BOOL.class) {
Type = type.ordinal() | EVT_VARIANT_TYPE_ARRAY;
Memory mem = new Memory(((BOOL[]) value).length * 4);
for (int i = 0; i < ((BOOL[]) value).length; i++) {
mem.setInt(i * 4, ((BOOL[]) value)[i].intValue());
}
holder = mem;
Count = 0;
field1.writeField("pointerValue", mem);
} else if (value.getClass() == BOOL.class) {
Type = type.ordinal();
Count = 0;
field1.writeField("intValue", ((BOOL) value).intValue());
} else {
throw new IllegalArgumentException(type.name() + " must be set from BOOL/BOOL[]");
}
break;
case EvtVarTypeString:
case EvtVarTypeEvtXml:
if (value.getClass().isArray() && value.getClass().getComponentType() == String.class) {
Type = type.ordinal() | EVT_VARIANT_TYPE_ARRAY;
StringArray sa = new StringArray((String[]) value, true);
holder = sa;
Count = ((String[]) value).length;
field1.writeField("pointerValue", sa);
} else if (value.getClass() == String.class) {
Type = type.ordinal();
Memory mem = new Memory((((String) value).length() + 1) * 2);
mem.setWideString(0, (String) value);
holder = mem;
Count = 0;
field1.writeField("pointerValue", mem);
} else {View on GitHub (pinned to d036ad9781)
Solutions
- Wrap the value: new BOOL(true) for a single value
- Convert arrays element-wise: BOOL[] arr = Arrays.stream(booleans).mapToObj(b -> new BOOL(b)).toArray(BOOL[]::new); or a loop for boolean[]
- If the value is java.lang.Boolean, call bool.booleanValue() first and wrap in BOOL
Example fix
// before variant.setValue(EVT_VARIANT_TYPE.EvtVarTypeBoolean, true); // after variant.setValue(EVT_VARIANT_TYPE.EvtVarTypeBoolean, new BOOL(true));
Defensive patterns
Strategy: type-guard
Validate before calling
boolean ok = value instanceof BOOL
|| (value != null && value.getClass() == BOOL[].class);
if (!ok) throw new IllegalArgumentException("Boolean variant needs BOOL/BOOL[]"); Type guard
boolean isBoolVariant(Object v) {
return v instanceof BOOL || (v != null && v.getClass() == BOOL[].class);
} Try / catch
try {
variant.setValue(EVT_VARIANT_TYPE.EvtVarTypeBoolean, value);
} catch (IllegalArgumentException e) {
variant.setValue(EVT_VARIANT_TYPE.EvtVarTypeBoolean,
new BOOL(((Boolean) value).booleanValue()));
} Prevention
- Always wrap booleans in com.sun.jna.platform.win32.BOOL for the Windows Event Log API
- Convert boolean[]/Boolean[] to BOOL[] before setValue
- Note that java.lang.Boolean and boolean[] are both rejected — this is JNA, not auto-boxing territory
When it happens
Trigger: setValue(EVT_VARIANT_TYPE.EvtVarTypeBoolean, Boolean.TRUE) or setValue(..., new boolean[]{true}) — the JNA wrapper demands its own com.sun.jna.platform.win32.BOOL wrapper type, not java.lang.Boolean or primitive boolean[].
Common situations: Passing Java's Boolean/boolean[] directly because the developer assumed auto-boxing support; constructing event values from JSON where booleans deserialize to java.lang.Boolean.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- must be set from String/String[]
- must be set from byte/byte[]
- must be set from short/short[]
- must be set from int/int[]
- must be set from long/long[]
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/838af68790add9c9.
Report an issue: GitHub.