{"record":{"id":"d7104944f35189ff","repo":"apache/seatunnel","slug":"field-set-failed","errorCode":null,"errorMessage":"field set failed","messagePattern":"field set failed","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/ReflectionUtils.java","lineNumber":75,"sourceCode":"                searchType = searchType.getSuperclass();\n            }\n            return Optional.empty();\n        } catch (IllegalAccessException | IllegalArgumentException e) {\n            return Optional.empty();\n        }\n    }\n\n    public static Optional<Object> getField(Object object, String fieldName) {\n        return getField(object, object.getClass(), fieldName);\n    }\n\n    public static void setField(Object object, Class<?> clazz, String fieldName, Object value) {\n        try {\n            Field field = clazz.getDeclaredField(fieldName);\n            field.setAccessible(true);\n            field.set(object, value);\n        } catch (NoSuchFieldException | IllegalAccessException e) {\n            throw new RuntimeException(\"field set failed\", e);\n        }\n    }\n\n    public static void setField(Object object, String fieldName, Object value) {\n        setField(object, object.getClass(), fieldName, value);\n    }\n\n    public static Object invoke(Object object, String methodName, Object... args) {\n        Class<?>[] argTypes = new Class[args.length];\n        for (int i = 0; i < args.length; i++) {\n            argTypes[i] = args[i].getClass();\n        }\n        return invoke(object, methodName, argTypes, args);\n    }\n\n    public static Object invoke(\n            Object object, String methodName, Class<?>[] argTypes, Object[] args) {\n        try {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/ReflectionUtils.java#L57-L93","documentation":"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).","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nReflectionUtils.setField(conn, \"delegate\", wrapped); // 'delegate' is on a superclass\n// after\nReflectionUtils.setField(conn, conn.getClass().getSuperclass(), \"delegate\", wrapped);","handlingStrategy":"try-catch","validationCode":"boolean hasField(Class<?> c, String name) {\n    for (Class<?> k = c; k != null; k = k.getSuperclass()) {\n        try { k.getDeclaredField(name); return true; } catch (NoSuchFieldException ignored) {}\n    }\n    return false;\n}","typeGuard":null,"tryCatchPattern":"try {\n    ReflectionUtils.setField(target, fieldName, value);\n} catch (RuntimeException e) {\n    throw new IllegalStateException(\"cannot set field '\" + fieldName + \"' on \" + target.getClass().getName(), e);\n}","preventionTips":["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"],"tags":["reflection","runtime-exception","access"],"backgroundTag":"internal-invariant-violation","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}