{"record":{"id":"adbf97003b30c599","repo":"java-native-access/jna","slug":"invalid-type","errorCode":null,"errorMessage":"Invalid type: ","messagePattern":"Invalid type: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java","lineNumber":2508,"sourceCode":"         * Event log type.\n         *\n         * @return Event log type.\n         */\n        public EventLogType getType() {\n            switch (_record.EventType.intValue()) {\n                case WinNT.EVENTLOG_SUCCESS:\n                case WinNT.EVENTLOG_INFORMATION_TYPE:\n                    return EventLogType.Informational;\n                case WinNT.EVENTLOG_AUDIT_FAILURE:\n                    return EventLogType.AuditFailure;\n                case WinNT.EVENTLOG_AUDIT_SUCCESS:\n                    return EventLogType.AuditSuccess;\n                case WinNT.EVENTLOG_ERROR_TYPE:\n                    return EventLogType.Error;\n                case WinNT.EVENTLOG_WARNING_TYPE:\n                    return EventLogType.Warning;\n                default:\n                    throw new RuntimeException(\"Invalid type: \"\n                            + _record.EventType.intValue());\n            }\n        }\n\n        /**\n         * Raw data associated with the record.\n         *\n         * @return Array of bytes or null.\n         */\n        public byte[] getData() {\n            return _data;\n        }\n\n        public EventLogRecord(Pointer pevlr) {\n            _record = new EVENTLOGRECORD(pevlr);\n            _source = pevlr.getWideString(_record.size());\n            // data\n            if (_record.DataLength.intValue() > 0) {","sourceCodeStart":2490,"sourceCodeEnd":2526,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java#L2490-L2526","documentation":"Advapi32Util.EventLogRecord.toType() maps a Windows event log record's EventType integer to the EventLogType enum. When the record's EventType does not match any of the known WinNT EVENTLOG_*_TYPE constants (e.g. EVENTLOG_SUCCESS, ERROR, WARNING, INFORMATION, AUDIT_SUCCESS, AUDIT_FAILURE), the default branch throws this RuntimeException because the library has no enum value to represent the type.","triggerScenarios":"Calling Advapi32Util.EventLogRecord.toType() on a record read via Advapi32's ReadEventLog whose EventType integer is not one of the six WinNT.EVENTLOG_*_TYPE constants (e.g. a vendor-defined or reserved event type value).","commonSituations":"Reading custom application event logs or third-party logs that use event types outside the standard Windows set; parsing old or unusual .evt/.evtx sources; Windows SDK adding newer event type values not yet mapped in the JNA binding.","solutions":["Catch the RuntimeException and fall back to using the raw getRecord().EventType value instead of the enum.","Log the unknown EventType integer and skip the record instead of converting its type.","Update/patch Advapi32Util to add the missing EventType mapping to EventLogType.","Upgrade JNA to the latest version in case new event types were added to the mapping."],"exampleFix":"// before\nEventLogType type = record.toType();\n// after\nEventLogType type;\ntry {\n    type = record.toType();\n} catch (RuntimeException e) {\n    type = EventLogType.Information; // or handle raw record.getRecord().EventType\n}","handlingStrategy":"try-catch","validationCode":"int eventType = record.getRecord().EventType.intValue();\nboolean known = eventType == WinNT.EVENTLOG_SUCCESS_TYPE || eventType == WinNT.EVENTLOG_AUDIT_FAILURE\n    || eventType == WinNT.EVENTLOG_AUDIT_SUCCESS || eventType == WinNT.EVENTLOG_ERROR_TYPE\n    || eventType == WinNT.EVENTLOG_INFORMATION_TYPE || eventType == WinNT.EVENTLOG_WARNING_TYPE;","typeGuard":"boolean isKnownEventLogType(int eventType) {\n    return eventType == WinNT.EVENTLOG_SUCCESS_TYPE || eventType == WinNT.EVENTLOG_AUDIT_FAILURE\n        || eventType == WinNT.EVENTLOG_AUDIT_SUCCESS || eventType == WinNT.EVENTLOG_ERROR_TYPE\n        || eventType == WinNT.EVENTLOG_INFORMATION_TYPE || eventType == WinNT.EVENTLOG_WARNING_TYPE;\n}","tryCatchPattern":"try {\n    EventLogType type = record.toType();\n} catch (RuntimeException e) {\n    int raw = record.getRecord().EventType.intValue();\n    log.warn(\"Unknown event log type \" + raw + \", skipping\");\n}","preventionTips":["Check the raw EventType integer against the WinNT.EVENTLOG_* constants before calling toType().","Log unknown event type values instead of letting them propagate.","Keep JNA updated so newly introduced Windows event types are mapped."],"tags":["windows","eventlog","enum-mapping","jna"],"backgroundTag":"invalid-enum-value","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"}