java-native-access/jna · error · RuntimeException
Invalid type:
Error message
Invalid type:
What it means
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.
Source
Thrown at contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java:2508
* Event log type.
*
* @return Event log type.
*/
public EventLogType getType() {
switch (_record.EventType.intValue()) {
case WinNT.EVENTLOG_SUCCESS:
case WinNT.EVENTLOG_INFORMATION_TYPE:
return EventLogType.Informational;
case WinNT.EVENTLOG_AUDIT_FAILURE:
return EventLogType.AuditFailure;
case WinNT.EVENTLOG_AUDIT_SUCCESS:
return EventLogType.AuditSuccess;
case WinNT.EVENTLOG_ERROR_TYPE:
return EventLogType.Error;
case WinNT.EVENTLOG_WARNING_TYPE:
return EventLogType.Warning;
default:
throw new RuntimeException("Invalid type: "
+ _record.EventType.intValue());
}
}
/**
* Raw data associated with the record.
*
* @return Array of bytes or null.
*/
public byte[] getData() {
return _data;
}
public EventLogRecord(Pointer pevlr) {
_record = new EVENTLOGRECORD(pevlr);
_source = pevlr.getWideString(_record.size());
// data
if (_record.DataLength.intValue() > 0) {View on GitHub (pinned to d036ad9781)
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.
Example fix
// before
EventLogType type = record.toType();
// after
EventLogType type;
try {
type = record.toType();
} catch (RuntimeException e) {
type = EventLogType.Information; // or handle raw record.getRecord().EventType
} Defensive patterns
Strategy: try-catch
Validate before calling
int eventType = record.getRecord().EventType.intValue();
boolean known = eventType == WinNT.EVENTLOG_SUCCESS_TYPE || eventType == WinNT.EVENTLOG_AUDIT_FAILURE
|| eventType == WinNT.EVENTLOG_AUDIT_SUCCESS || eventType == WinNT.EVENTLOG_ERROR_TYPE
|| eventType == WinNT.EVENTLOG_INFORMATION_TYPE || eventType == WinNT.EVENTLOG_WARNING_TYPE; Type guard
boolean isKnownEventLogType(int eventType) {
return eventType == WinNT.EVENTLOG_SUCCESS_TYPE || eventType == WinNT.EVENTLOG_AUDIT_FAILURE
|| eventType == WinNT.EVENTLOG_AUDIT_SUCCESS || eventType == WinNT.EVENTLOG_ERROR_TYPE
|| eventType == WinNT.EVENTLOG_INFORMATION_TYPE || eventType == WinNT.EVENTLOG_WARNING_TYPE;
} Try / catch
try {
EventLogType type = record.toType();
} catch (RuntimeException e) {
int raw = record.getRecord().EventType.intValue();
log.warn("Unknown event log type " + raw + ", skipping");
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- LookupAccountNameW was expected to fail with ERROR_INSUFFICI
- Expected GetTokenInformation to fail with ERROR_INSUFFICIENT
- Unexpected registry type + lpType.getValue() + , expected RE
- SECURITY_DESCRIPTOR_RELATIVE does not contain owner
- Owner PSID is invalid
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/adbf97003b30c599.
Report an issue: GitHub.