{"record":{"id":"fa5f73e7a3b36600","repo":"java-native-access/jna","slug":"must-be-set-from-byte-byte","errorCode":null,"errorMessage":" must be set from byte/byte[]","messagePattern":" must be set from byte/byte\\[\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/Winevt.java","lineNumber":352,"sourceCode":"                        } else {\n                            throw new IllegalArgumentException(type.name() + \" must be set from String/String[]\");\n                        }\n                        break;\n                    case EvtVarTypeSByte:\n                    case EvtVarTypeByte:\n                        if (value.getClass().isArray() && value.getClass().getComponentType() == byte.class) {\n                            Type = type.ordinal() | EVT_VARIANT_TYPE_ARRAY;\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 if (value.getClass() == byte.class) {\n                            Type = type.ordinal();\n                            Count = 0;\n                            field1.writeField(\"byteValue\", value);\n                        } else {\n                            throw new IllegalArgumentException(type.name() + \" must be set from byte/byte[]\");\n                        }\n                        break;\n                    case EvtVarTypeInt16:\n                    case EvtVarTypeUInt16:\n                        if (value.getClass().isArray() && value.getClass().getComponentType() == short.class) {\n                            Type = type.ordinal() | EVT_VARIANT_TYPE_ARRAY;\n                            Memory mem = new Memory(((short[]) value).length * 2);\n                            mem.write(0, (short[]) value, 0, ((short[]) value).length);\n                            holder = mem;\n                            Count = 0;\n                            field1.writeField(\"pointerValue\", mem);\n                        } else if (value.getClass() == short.class) {\n                            Type = type.ordinal();\n                            Count = 0;\n                            field1.writeField(\"shortValue\", value);\n                        } else {\n                            throw new IllegalArgumentException(type.name() + \" must be set from short/short[]\");\n                        }","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/Winevt.java#L334-L370","documentation":"For EvtVarTypeSByte and EvtVarTypeByte, setValue accepts a byte[] (array form) or a single byte (stored in byteValue). Values of other types raise IllegalArgumentException '<TypeName> must be set from byte/byte[]'.","triggerScenarios":"setValue(EVT_VARIANT_TYPE.EvtVarTypeByte, Byte.valueOf((byte)1)) or passing an int/Integer/byte-buffer contents instead of a primitive byte or byte[].","commonSituations":"Passing a ByteBuffer's backing data without array(); passing Integer parsed from config for a byte-typed channel property; passing Byte wrapper object which fails the getClass() == byte.class check.","solutions":["Pass a primitive byte (autoboxing to Byte will NOT pass the check, so use byte[] or ensure exact class)","Wrap a single value in a one-element array: new byte[]{ b }","Convert numeric types with an explicit cast: (byte) intValue, or copy ByteBuffer via buf.get(new byte[buf.remaining()])"],"exampleFix":"// before\nvariant.setValue(EVT_VARIANT_TYPE.EvtVarTypeByte, byteBuffer);\n// after\nbyte[] bytes = new byte[byteBuffer.remaining()];\nbyteBuffer.get(bytes);\nvariant.setValue(EVT_VARIANT_TYPE.EvtVarTypeByte, bytes);","handlingStrategy":"type-guard","validationCode":"boolean ok = value instanceof Byte\n    ? false /* wrapper rejected: check exact class */\n    : value != null && (value.getClass() == byte.class || value.getClass() == byte[].class);\nif (value instanceof Byte) value = new byte[]{ ((Byte) value).byteValue() };","typeGuard":"boolean isByteVariant(Object v) {\n    return v != null && (v.getClass() == byte.class || v.getClass() == byte[].class);\n}","tryCatchPattern":"try {\n    variant.setValue(EVT_VARIANT_TYPE.EvtVarTypeByte, value);\n} catch (IllegalArgumentException e) {\n    variant.setValue(EVT_VARIANT_TYPE.EvtVarTypeByte, new byte[]{ ((Number) value).byteValue() });\n}","preventionTips":["Copy ByteBuffer contents into byte[] before setValue","Cast numerics with (byte) and wrap single values in byte[]{...}","Wrapper Byte objects fail the exact-class check — use primitive arrays"],"tags":["windows-eventlog","jna","type-mismatch"],"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"}