apache/dolphinscheduler · error · IllegalArgumentException

invalid code :

Error message

invalid code : 

What it means

OptionSourceType.of(Integer) throws IllegalArgumentException when the given code is not in VALUES_MAP. OptionSourceType categorizes where a data-quality option value originates (e.g. fixed value vs from a dataset column); an unmapped code means the option source type in data-quality task parameters is not recognized by this build.

Source

Thrown at dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/enums/dp/OptionSourceType.java:70

    }

    public String getDescription() {
        return description;
    }

    private static final Map<Integer, OptionSourceType> VALUES_MAP = new HashMap<>();

    static {
        for (OptionSourceType type : OptionSourceType.values()) {
            VALUES_MAP.put(type.code, type);
        }
    }

    public static OptionSourceType of(Integer status) {
        if (VALUES_MAP.containsKey(status)) {
            return VALUES_MAP.get(status);
        }
        throw new IllegalArgumentException("invalid code : " + status);
    }
}

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Verify the option source type code in the data-quality parameters matches an OptionSourceType constant and fix it.
  2. Use OptionSourceType enum constants when generating parameter JSON.
  3. Re-map stored codes to current enum values after DolphinScheduler upgrades.
  4. Validate the code against OptionSourceType's map before calling of() when the value comes from user input.

Example fix

// before
OptionSourceType sourceType = OptionSourceType.of(option.getInteger("sourceType"));

// after: null-safe with validation
Integer code = option.getInteger("sourceType");
OptionSourceType sourceType = (code == null) ? OptionSourceType.DEFAULT
        : OptionSourceType.of(code);
Defensive patterns

Strategy: validation

Validate before calling

static boolean isKnownOptionSourceType(Integer code) {
    return code != null && Arrays.stream(OptionSourceType.values()).anyMatch(t -> t.getCode().equals(code));
}

Type guard

static Optional<OptionSourceType> safeOf(Integer status) {
    if (status == null) return Optional.empty();
    return Arrays.stream(OptionSourceType.values())
            .filter(t -> t.getCode().equals(status))
            .findFirst();
}

Try / catch

try {
    sourceType = OptionSourceType.of(code);
} catch (IllegalArgumentException e) {
    log.warn("Unknown option source type {}, using default", code);
    sourceType = OptionSourceType.DEFAULT;
}

Prevention

When it happens

Trigger: Calling OptionSourceType.of() with an Integer missing from VALUES_MAP — typically when the options section of data-quality task parameters contains an unknown source type, or parameter templates written for another enum/version are reused.

Common situations: Hand-editing data-quality options JSON; API clients sending wrong numeric option source types; version skew between workflow definitions persisted earlier and the current enum definitions.

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 apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/d7001e3d5c6c9afc. Report an issue: GitHub.