{"record":{"id":"19bdce3eed95a495","repo":"java-native-access/jna","slug":"must-be-set-from-long-long","errorCode":null,"errorMessage":" must be set from long/long[]","messagePattern":" must be set from long/long\\[\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/Winevt.java","lineNumber":405,"sourceCode":"                            throw new IllegalArgumentException(type.name() + \" must be set from int/int[]\");\n                        }\n                        break;\n                    case EvtVarTypeHexInt64:\n                    case EvtVarTypeInt64:\n                    case EvtVarTypeUInt64:\n                        if (value.getClass().isArray() && value.getClass().getComponentType() == long.class) {\n                            Type = type.ordinal() | EVT_VARIANT_TYPE_ARRAY;\n                            Memory mem = new Memory(((long[]) value).length * 4);\n                            mem.write(0, (long[]) value, 0, ((long[]) value).length);\n                            holder = mem;\n                            Count = 0;\n                            field1.writeField(\"pointerValue\", mem);\n                        } else if (value.getClass() == long.class) {\n                            Type = type.ordinal();\n                            Count = 0;\n                            field1.writeField(\"longValue\", value);\n                        } else {\n                            throw new IllegalArgumentException(type.name() + \" must be set from long/long[]\");\n                        }\n                        break;\n                    case EvtVarTypeSingle:\n                        if (value.getClass().isArray() && value.getClass().getComponentType() == float.class) {\n                            Type = type.ordinal() | EVT_VARIANT_TYPE_ARRAY;\n                            Memory mem = new Memory(((float[]) value).length * 4);\n                            mem.write(0, (float[]) value, 0, ((float[]) value).length);\n                            holder = mem;\n                            Count = 0;\n                            field1.writeField(\"pointerValue\", mem);\n                        } else if (value.getClass() == float.class) {\n                            Type = type.ordinal();\n                            Count = 0;\n                            field1.writeField(\"floatValue\", value);\n                        } else {\n                            throw new IllegalArgumentException(type.name() + \" must be set from float/float[]\");\n                        }\n                        break;","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/Winevt.java#L387-L423","documentation":"For EvtVarTypeHexInt64, EvtVarTypeInt64 and EvtVarTypeUInt64, setValue requires a primitive long (getClass() == long.class) or a long[] array. Other types raise IllegalArgumentException '<TypeName> must be set from long/long[]'.","triggerScenarios":"setValue(EVT_VARIANT_TYPE.EvtVarTypeUInt64, intValue) — an int passed for a 64-bit field; or an Integer/Long boxed in a collection so getClass() is the wrapper class.","commonSituations":"Timestamps or file times kept as Integer; values from List<Long> converted with toArray() giving Long[]; BigIntegers from parsing hex strings.","solutions":["Cast to long: (long) intValue — widening is safe for signed values","Convert List<Long>/Long[] to long[] with a loop or Arrays.stream(longBoxed).mapToLong(Long::longValue).toArray()","For BigInteger use bigInteger.longValueExact() to avoid silent truncation"],"exampleFix":"// before\nvariant.setValue(EVT_VARIANT_TYPE.EvtVarTypeUInt64, integerList.toArray()); // Integer[]\n// after\nlong[] longs = new long[integerList.size()];\nfor (int i = 0; i < longs.length; i++) longs[i] = integerList.get(i).longValue();\nvariant.setValue(EVT_VARIANT_TYPE.EvtVarTypeUInt64, longs);","handlingStrategy":"type-guard","validationCode":"if (value instanceof Integer) value = (long) (Integer) value;\nelse if (value instanceof BigInteger) value = ((BigInteger) value).longValueExact();","typeGuard":"boolean isLongVariant(Object v) {\n    return v != null && (v.getClass() == long.class || v.getClass() == long[].class);\n}","tryCatchPattern":"try {\n    variant.setValue(EVT_VARIANT_TYPE.EvtVarTypeUInt64, value);\n} catch (IllegalArgumentException e) {\n    variant.setValue(EVT_VARIANT_TYPE.EvtVarTypeUInt64, ((Number) value).longValue());\n}","preventionTips":["Widen ints to long explicitly before setting 64-bit variants","Use longValueExact() for BigInteger to avoid silent truncation","Convert boxed Long collections to primitive long[] 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"}