{"record":{"id":"a01e214c0730f9d0","repo":"java-native-access/jna","slug":"must-be-set-from-byte","errorCode":null,"errorMessage":" must be set from byte[]","messagePattern":" must be set from byte\\[\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/Winevt.java","lineNumber":449,"sourceCode":"                            field1.writeField(\"pointerValue\", mem);\n                        } else if (value.getClass() == double.class) {\n                            Type = type.ordinal();\n                            Count = 0;\n                            field1.writeField(\"doubleVal\", value);\n                        } else {\n                            throw new IllegalArgumentException(type.name() + \" must be set from double/double[]\");\n                        }\n                        break;\n                    case EvtVarTypeBinary:\n                        if (value.getClass().isArray() && value.getClass().getComponentType() == byte.class) {\n                            Type = type.ordinal();\n                            Memory mem = new Memory(((byte[]) value).length * 1);\n                            mem.write(0, (byte[]) value, 0, ((byte[]) value).length);\n                            holder = mem;\n                            Count = 0;\n                            field1.writeField(\"pointerValue\", mem);\n                        } else {\n                            throw new IllegalArgumentException(type.name() + \" must be set from byte[]\");\n                        }\n                        break;\n                    case EvtVarTypeFileTime:\n                    case EvtVarTypeEvtHandle:\n                    case EvtVarTypeSysTime:\n                    case EvtVarTypeGuid:\n                    case EvtVarTypeSid:\n                    case EvtVarTypeSizeT:\n                    default:\n                        throw new IllegalStateException(String.format(\"NOT IMPLEMENTED: getValue(%s) (Array: %b, Count: %d)\", type, isArray(), Count));\n                }\n            }\n            write();\n        }\n\n        /**\n         * @return value contained in the EVT_VARIANT\n         */","sourceCodeStart":431,"sourceCodeEnd":467,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/Winevt.java#L431-L467","documentation":"This IllegalArgumentException is thrown by Winevt.EVT_VARIANT.setValue when the variant's EvtVarType is one that requires the value to be supplied as a byte[] (raw binary data), but the caller passed a value of an incompatible Java type (e.g. a String, Integer, or pointer-like object) instead of a byte array. The library only knows how to marshal byte-backed payloads for these variant types and refuses to guess. It is a caller type error, not a Win32 failure.","triggerScenarios":"Calling EVT_VARIANT.setValue() on a variant whose type is EvtVarTypeBinary (or another byte[]-only type) with a non-byte[] argument, e.g. setValue(\"someString\") instead of setValue(someString.getBytes()). Seen from testModifyChannelConfig when writing channel configuration values with a mismatched type.","commonSituations":"Setting an event-channel config property where the developer assumes String or integer values are accepted; converting config values read via getValue() (which may return String/Integer) and writing them back without converting to byte[]; JNA version changes that tightened setValue type handling.","solutions":["Pass a byte[] to setValue(), e.g. value.getBytes(StandardCharsets.UTF_8) for string data or a properly encoded buffer for binary data","Check the variant's EvtVarType first and only supply the Java type that type maps to (map String<->EvtVarTypeString, Integer<->EvtVarTypeUInt32/Int32, byte[]<->EvtVarTypeBinary)","If the target type is not byte[], change the variant type or use the appropriate setValue branch instead of forcing binary marshalling","Wrap the write in try/catch (IllegalArgumentException) during config modification to fail gracefully and log the offending type"],"exampleFix":"// before\nvariant.setValue(\"604800\");\n// after\nvariant.setValue(\"604800\".getBytes(StandardCharsets.UTF_8));","handlingStrategy":"type-guard","validationCode":"if (!(value instanceof byte[])) {\n    throw new IllegalArgumentException(\"EvtVarTypeBinary requires byte[], got \" + value.getClass());\n}","typeGuard":"boolean isBinaryWritable(EVT_VARIANT v, Object val) {\n    return v.type == Winevt.EvtVarTypeBinary && val instanceof byte[];\n}","tryCatchPattern":"try {\n    variant.setValue(val);\n} catch (IllegalArgumentException e) {\n    log.warn(\"setValue type mismatch: \" + e.getMessage());\n}","preventionTips":["Always map EvtVarType to the matching Java type before setValue","Convert strings to byte[] explicitly with a fixed charset","Unit-test config write paths against each EvtVarType"],"tags":["jna","windows-eventlog","type-mismatch","illegal-argument"],"backgroundTag":"type-mismatch","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"}