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

  1. Catch the RuntimeException and fall back to using the raw getRecord().EventType value instead of the enum.
  2. Log the unknown EventType integer and skip the record instead of converting its type.
  3. Update/patch Advapi32Util to add the missing EventType mapping to EventLogType.
  4. 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

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


AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12). Data as JSON: /api/errors/adbf97003b30c599. Report an issue: GitHub.