jd-opensource/joyagent-jdgenie · error · IllegalArgumentException

不支持的操作类型:

Error message

不支持的操作类型:

What it means

ComparisonType.of(String) maps a string to the ComparisonType enum by case-insensitive name match; if no enum constant matches, it throws IllegalArgumentException with '不支持的操作类型:' plus the input. It is a strict enum-parse guard against unknown operator names.

Solutions

  1. Check the ComparisonType enum constants and send an exact (case-insensitive) name, e.g. EQUAL, NOT_EQUAL, GREATER_THAN
  2. Validate/normalize the operator string client-side against the enum names before calling of()
  3. Wrap of() in try-catch to return a default or a clear 400 error naming valid options
  4. If a new operator is genuinely needed, add a constant to ComparisonType and redeploy

Example fix

// before
ComparisonType type = ComparisonType.of(request.getOperator()); // "gt"
// after
String op = request.getOperator().trim().toUpperCase().replace("GT", "GREATER_THAN");
ComparisonType type;
try {
    type = ComparisonType.of(op);
} catch (IllegalArgumentException e) {
    throw new IllegalArgumentException("operator must be one of " + Arrays.toString(ComparisonType.values()));
}
Defensive patterns

Strategy: validation

Validate before calling

Set<String> valid = Arrays.stream(ComparisonType.values())
    .map(Enum::name).collect(Collectors.toSet());
if (operator == null || !valid.contains(operator.trim().toUpperCase())) {
    throw new IllegalArgumentException("Unknown operator: " + operator + ", valid: " + valid);
}
ComparisonType type = ComparisonType.of(operator.trim());

Type guard

Optional<ComparisonType> tryParse(String s) {
    return s == null ? Optional.empty()
        : Arrays.stream(ComparisonType.values())
            .filter(t -> t.name().equalsIgnoreCase(s.trim()))
            .findFirst();
}

Try / catch

try {
    ComparisonType type = ComparisonType.of(operator);
} catch (IllegalArgumentException e) {
    return ResponseEntity.badRequest().body("Unknown operator; valid values: "
        + Arrays.toString(ComparisonType.values()));
}

Prevention

When it happens

Trigger: Calling ComparisonType.of with any string that is not exactly (ignoring case) a ComparisonType constant name — e.g. 'great_than', 'gt', 'eq' vs expected names like 'EQUAL', 'GREATER_THAN'.

Common situations: User-supplied filter/operator from a request payload not matching backend enum names; frontend sends Chinese or shorthand operators; older clients using renamed operators after a version change.

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/87cdaa12c623563b. Report an issue: GitHub.

Appendix: source

Thrown at genie-backend/src/main/java/com/jd/genie/data/model/ComparisonType.java:63

    ComparisonType(String comparison, String comparisonName,String relationalAlgebra,String relationalAlgebraSql) {
        this.comparison = comparison;
        this.comparisonName = comparisonName;
        this.relationalAlgebra = relationalAlgebra;
        this.relationalAlgebraSql = relationalAlgebraSql;
    }


    public static ComparisonType of(String var0) {
        ComparisonType[] var1 = ComparisonType.class.getEnumConstants();

        for (ComparisonType var4 : var1) {
            if (StringUtils.equalsIgnoreCase(var0, var4.name())) {
                return var4;
            }
        }

        throw new IllegalArgumentException("不支持的操作类型:" + var0);
    }
}

View on GitHub (pinned to 2417e0b8b6)