{"record":{"id":"00ffe56c4a65a9f2","repo":"java-native-access/jna","slug":"must-be-set-from-float-float","errorCode":null,"errorMessage":" must be set from float/float[]","messagePattern":" must be set from float/float\\[\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/Winevt.java","lineNumber":421,"sourceCode":"                            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;\n                    case EvtVarTypeDouble:\n                        if (value.getClass().isArray() && value.getClass().getComponentType() == double.class) {\n                            Type = type.ordinal() | EVT_VARIANT_TYPE_ARRAY;\n                            Memory mem = new Memory(((double[]) value).length * 4);\n                            mem.write(0, (double[]) value, 0, ((double[]) value).length);\n                            holder = mem;\n                            Count = 0;\n                            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;","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/Winevt.java#L403-L439","documentation":"For EvtVarTypeSingle (32-bit float), setValue requires a primitive float (getClass() == float.class) or a float[] array. Other types raise IllegalArgumentException '<TypeName> must be set from float/float[]'.","triggerScenarios":"setValue(EVT_VARIANT_TYPE.EvtVarTypeSingle, doubleValue) — a double passed for a float field; or a Float/Double wrapper object, since getClass() must be exactly float.class.","commonSituations":"Measurements parsed with Double.parseDouble; values from JSON deserialized as Double; math expressions that default to double precision.","solutions":["Cast to float: (float) doubleValue (accepting precision loss)","Convert double[] to float[] element-wise in a loop or with Float.parseFloat(String.valueOf(d)) for exactness control","Ensure boxed Float values are unboxed: floatValue.floatValue() — but note a single primitive float must be passed, wrap in float[] if needed"],"exampleFix":"// before\nvariant.setValue(EVT_VARIANT_TYPE.EvtVarTypeSingle, doubleValue);\n// after\nvariant.setValue(EVT_VARIANT_TYPE.EvtVarTypeSingle, (float) doubleValue);","handlingStrategy":"type-guard","validationCode":"if (value instanceof Double) value = (float) ((Double) value).doubleValue();\nelse if (!(value instanceof Float)) value = (float) ((Number) value).doubleValue();","typeGuard":"boolean isFloatVariant(Object v) {\n    return v != null && (v.getClass() == float.class || v.getClass() == float[].class);\n}","tryCatchPattern":"try {\n    variant.setValue(EVT_VARIANT_TYPE.EvtVarTypeSingle, value);\n} catch (IllegalArgumentException e) {\n    variant.setValue(EVT_VARIANT_TYPE.EvtVarTypeSingle, (float) ((Number) value).doubleValue());\n}","preventionTips":["Cast doubles to float when setting EvtVarTypeSingle","Remember double math results must be narrowed with (float)","Convert Double[] collections to primitive float[] before the call"],"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-19T12:17:13.211Z"}