jd-opensource/joyagent-jdgenie · error · IllegalArgumentException

不支持类型

Error message

不支持类型

What it means

EventTypeEnum.of(type) iterates all enum constants and returns the one whose name case-insensitively matches; if no constant matches, it throws an IllegalArgumentException with the generic message 不支持类型 (unsupported type). The thrown message does not even include the offending value, making diagnosis harder.

Solutions

  1. Log or include the offending type string in the exception message to identify the bad value
  2. Normalize the input (trim, remove spaces/dashes) before calling of()
  3. Add the missing constant to EventTypeEnum if the type is a legitimate new value
  4. Use a from-value mapping that tolerates aliases instead of exact name matching

Example fix

// before
EventTypeEnum eventType = EventTypeEnum.of(request.getType()); // IllegalArgumentException: 不支持类型
// after
String normalized = request.getType() == null ? null : request.getType().trim().replace("-", "_");
EventTypeEnum eventType = EventTypeEnum.of(normalized); // or add try/catch with a clear message
Defensive patterns

Strategy: try-catch

Validate before calling

boolean known = java.util.Arrays.stream(EventTypeEnum.class.getEnumConstants())
    .anyMatch(e -> e.name().equalsIgnoreCase(type));
if (!known) {
    throw new IllegalArgumentException("Unknown event type: " + type);
}

Type guard

java.util.Optional<EventTypeEnum> tryOf(String type) {
    return java.util.Arrays.stream(EventTypeEnum.class.getEnumConstants())
        .filter(e -> org.apache.commons.lang3.StringUtils.equalsIgnoreCase(type, e.name()))
        .findFirst();
}

Try / catch

try {
    EventTypeEnum t = EventTypeEnum.of(type);
} catch (IllegalArgumentException e) {
    log.warn("Unknown event type '{}', using default", type);
    EventTypeEnum t = EventTypeEnum.DEFAULT; // or reject the request with a clear message
}

Prevention

When it happens

Trigger: Calling EventTypeEnum.of with a type string that is not exactly (case-insensitive) one of the enum constant names — e.g. misspelled names, different naming conventions (kebab-case vs camelCase), localized Chinese labels, or legacy/removed enum values stored in old data.

Common situations: Old records in the database contain event type strings that were renamed or removed from the enum; frontend sends a display label instead of the enum name; API consumers use different casing/format than the enum constants.

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 jd-opensource/joyagent-jdgenie@2417e0b8b6 (2026-09-08). Data as JSON: /api/errors/ae649c1e487d9346. Report an issue: GitHub.

Appendix: source

Thrown at genie-backend/src/main/java/com/jd/genie/model/enums/EventTypeEnum.java:33

     * 用户可输入
     */
    READY,
    /**
     * 异常
     */
    ERROR,
    /**
     * debug信息
     */
    DEBUG;

    public static EventTypeEnum of(String type) {
        for (EventTypeEnum authType : EventTypeEnum.class.getEnumConstants()) {
            if (StringUtils.equalsIgnoreCase(type, authType.name())) {
                return authType;
            }
        }
        throw new IllegalArgumentException("不支持类型");
    }
}

View on GitHub (pinned to 2417e0b8b6)