{"record":{"id":"7ecb87b4a8b1b961","repo":"java-native-access/jna","slug":"must-be-set-from-short-short","errorCode":null,"errorMessage":" must be set from short/short[]","messagePattern":" must be set from short/short\\[\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/Winevt.java","lineNumber":369,"sourceCode":"                        } 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                        }\n                        break;\n                    case EvtVarTypeHexInt32:\n                    case EvtVarTypeInt32:\n                    case EvtVarTypeUInt32:\n                        if (value.getClass().isArray() && value.getClass().getComponentType() == int.class) {\n                            Type = type.ordinal() | EVT_VARIANT_TYPE_ARRAY;\n                            Memory mem = new Memory(((int[]) value).length * 4);\n                            mem.write(0, (int[]) value, 0, ((int[]) value).length);\n                            holder = mem;\n                            Count = 0;\n                            field1.writeField(\"pointerValue\", mem);\n                        } else if (value.getClass() == int.class) {\n                            Type = type.ordinal();\n                            Count = 0;\n                            field1.writeField(\"intValue\", value);\n                        } else {\n                            throw new IllegalArgumentException(type.name() + \" must be set from int/int[]\");","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/Winevt.java#L351-L387","documentation":"For EvtVarTypeInt16 and EvtVarTypeUInt16, setValue requires a short (primitive, checked via getClass() == short.class) or a short[] for arrays. Any other type raises IllegalArgumentException '<TypeName> must be set from short/short[]'.","triggerScenarios":"setValue(EVT_VARIANT_TYPE.EvtVarTypeInt16, (Object) Integer.valueOf(5)) — an int/Integer passed where a 16-bit value is expected, since auto-widening does not happen because the parameter is Object.","commonSituations":"Parsing config values with Integer.parseInt and passing the int directly; passing Short wrapper object boxed from a collection; reading a value from JSON where numbers become Integer/Long.","solutions":["Cast explicitly to short: (short) intValue, then pass it (a literal short survives as short.class)","Convert arrays: loop or copy into short[] with per-element (short) casts","For Long values, check range (0..65535 for unsigned) before casting to short"],"exampleFix":"// before\nvariant.setValue(EVT_VARIANT_TYPE.EvtVarTypeInt16, intValue);\n// after\nvariant.setValue(EVT_VARIANT_TYPE.EvtVarTypeInt16, (short) intValue);","handlingStrategy":"type-guard","validationCode":"if (value instanceof Integer) value = (short) ((Integer) value).intValue();\nelse if (value instanceof Long) value = (short) ((Long) value).longValue();","typeGuard":"boolean isShortVariant(Object v) {\n    return v != null && (v.getClass() == short.class || v.getClass() == short[].class);\n}","tryCatchPattern":"try {\n    variant.setValue(EVT_VARIANT_TYPE.EvtVarTypeInt16, value);\n} catch (IllegalArgumentException e) {\n    variant.setValue(EVT_VARIANT_TYPE.EvtVarTypeInt16,\n        (short) ((Number) value).shortValue());\n}","preventionTips":["Explicitly cast ints/longs to short before setting 16-bit variants","Validate range (Int16: -32768..32767; UInt16: 0..65535) before casting","Convert boxed collections to primitive short[] before passing"],"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"}