apache/seatunnel · error · RuntimeException
field set failed
Error message
field set failed
What it means
ReflectionUtils.setField reflectively assigns a value to a declared field on the given class. It throws this RuntimeException when the field does not exist on the class (NoSuchFieldException) or is not accessible/writable (IllegalAccessException).
Source
Thrown at seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/ReflectionUtils.java:75
searchType = searchType.getSuperclass();
}
return Optional.empty();
} catch (IllegalAccessException | IllegalArgumentException e) {
return Optional.empty();
}
}
public static Optional<Object> getField(Object object, String fieldName) {
return getField(object, object.getClass(), fieldName);
}
public static void setField(Object object, Class<?> clazz, String fieldName, Object value) {
try {
Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
field.set(object, value);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException("field set failed", e);
}
}
public static void setField(Object object, String fieldName, Object value) {
setField(object, object.getClass(), fieldName, value);
}
public static Object invoke(Object object, String methodName, Object... args) {
Class<?>[] argTypes = new Class[args.length];
for (int i = 0; i < args.length; i++) {
argTypes[i] = args[i].getClass();
}
return invoke(object, methodName, argTypes, args);
}
public static Object invoke(
Object object, String methodName, Class<?>[] argTypes, Object[] args) {
try {View on GitHub (pinned to cf67b549a7)
Solutions
- Verify the exact field name and that it is declared on the class you pass — walk up the hierarchy or pass the declaring superclass
- Check the chained cause: NoSuchFieldException = wrong name/class; IllegalAccessException = access/JDK module restriction
- On JDK 9+, add --add-opens flags if the target is an encapsulated JDK/internal class
- Update the reflection target after library upgrades, or prefer a setter/public API instead of reflection
Example fix
// before ReflectionUtils.setField(conn, "delegate", wrapped); // 'delegate' is on a superclass // after ReflectionUtils.setField(conn, conn.getClass().getSuperclass(), "delegate", wrapped);
Defensive patterns
Strategy: try-catch
Validate before calling
boolean hasField(Class<?> c, String name) {
for (Class<?> k = c; k != null; k = k.getSuperclass()) {
try { k.getDeclaredField(name); return true; } catch (NoSuchFieldException ignored) {}
}
return false;
} Try / catch
try {
ReflectionUtils.setField(target, fieldName, value);
} catch (RuntimeException e) {
throw new IllegalStateException("cannot set field '" + fieldName + "' on " + target.getClass().getName(), e);
} Prevention
- Confirm the field name exists on the exact class or pass the declaring superclass
- Avoid reflecting into JDK/internal classes on JDK 9+; add --add-opens only as a last resort
- Re-verify reflection targets after any dependency upgrade; prefer setters/public APIs
When it happens
Trigger: Calling ReflectionUtils.setField(object, fieldName, value) (or the Class<?> overload) when fieldName is misspelled or doesn't exist on that class, the field exists on a superclass but not on object.getClass(), or the JVM blocks setAccessible (module access / SecurityManager / Java 9+ strong encapsulation of JDK internals).
Common situations: Patching internals of a library after a version upgrade renamed the field, trying to set inherited fields without passing the declaring superclass, testing framework code accessing JDK fields (e.g. java.lang) on newer JDKs, typos in field names.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Object to json exception!
- Json parse object exception!
- Json parse list exception!
- method invoke failed, no such method '%s' in '%s'
- method invoke failed
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/d7104944f35189ff.
Report an issue: GitHub.