apache/seatunnel · error · IllegalArgumentException

can't find field [ ]

Error message

can't find field [%s]

What it means

SeaTunnelRowType.indexOf(fieldName, throwExceptionWhenNotFound) scans fieldNames for an exact match and throws IllegalArgumentException when the field is absent and exception mode is on. It's the standard way to resolve a column name to an index in a row type.

Solutions

  1. Verify the exact field name against rowType.getFieldNames() and fix casing/spelling
  2. Use indexOf(fieldName, false) to probe existence (returns -1) before strict access
  3. Compare with the output of the previous transform — schema changes upstream may have renamed fields
  4. Use case-insensitive matching yourself by scanning getFieldNames() if the source has inconsistent casing

Example fix

// before
int idx = rowType.indexOf("userName", true); // throws if field absent
// after
int idx = rowType.indexOf("userName", false);
if (idx < 0) {
    idx = rowType.indexOf("user_name", true); // fallback naming convention
}
Defensive patterns

Strategy: validation

Validate before calling

int idx = rowType.indexOf(fieldName, false);
if (idx < 0) {
    throw new ConfigException("Column '" + fieldName + "' not in schema: "
        + Arrays.toString(rowType.getFieldNames()));
}

Try / catch

try {
    int idx = rowType.indexOf(name, true);
} catch (IllegalArgumentException e) {
    // resolve case-insensitively or fail with schema context
}

Prevention

When it happens

Trigger: Calling indexOf("col", true), or the strict wrappers (fieldIndex, requireFieldIndex, index, etc.), with a column name that does not exactly equal any field name in the SeaTunnelRowType — including case or whitespace differences.

Common situations: Upstream schema changed and a column was renamed/dropped; lookup with the wrong casing ('Name' vs 'name'); key-by-name lookups in sinks/transforms where config column names don't match the declared schema.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/f3f2f7128a29bab2. Report an issue: GitHub.

Appendix: source

Thrown at seatunnel-api/src/main/java/org/apache/seatunnel/api/table/type/SeaTunnelRowType.java:87

        return fieldNames[index];
    }

    public SeaTunnelDataType<?> getFieldType(int index) {
        return fieldTypes[index];
    }

    public int indexOf(String fieldName) {
        return indexOf(fieldName, true);
    }

    public int indexOf(String fieldName, boolean throwExceptionWhenNotFound) {
        for (int i = 0; i < fieldNames.length; i++) {
            if (fieldNames[i].equals(fieldName)) {
                return i;
            }
        }
        if (throwExceptionWhenNotFound) {
            throw new IllegalArgumentException(String.format("can't find field [%s]", fieldName));
        } else {
            return -1;
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof SeaTunnelRowType)) {
            return false;
        }
        SeaTunnelRowType that = (SeaTunnelRowType) obj;
        return Arrays.equals(fieldNames, that.fieldNames)
                && Arrays.equals(fieldTypes, that.fieldTypes);
    }

View on GitHub (pinned to cf67b549a7)