apache/flink · error · NonSerializableUserCodeException

User-defined object {} ({}) contains non-serializable field

Error message

User-defined object {} ({}) contains non-serializable field {} = {}

What it means

Error "User-defined object {} ({}) contains non-serializable field {} = {}" thrown in apache/flink.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/common/operators/util/UserCodeObjectWrapper.java:95

                }

                for (Field f : current.getClass().getDeclaredFields()) {
                    f.setAccessible(true);

                    if (f.getName().contains("$outer")) {
                        newCurrent = f.get(current);
                    }

                    if (hasCustomSerialization
                            || Modifier.isTransient(f.getModifiers())
                            || Modifier.isStatic(f.getModifiers())) {
                        // field not relevant for serialization
                        continue;
                    }

                    Object fieldContents = f.get(current);
                    if (fieldContents != null && !(fieldContents instanceof Serializable)) {
                        throw new NonSerializableUserCodeException(
                                "User-defined object "
                                        + userCodeObject
                                        + " ("
                                        + userCodeObject.getClass().getName()
                                        + ") contains non-serializable field "
                                        + f.getName()
                                        + " = "
                                        + f.get(current));
                    }
                }
                current = newCurrent;
            }
        } catch (NonSerializableUserCodeException e) {
            // forward those
            throw e;
        } catch (Exception e) {
            // should never happen, since we make the fields accessible.
            // anyways, do not swallow the exception, but report it

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Address the cause reported by the error message: User-defined object the reported value (the reported value) contains non-serializable field the reported value = the reported value
  2. Verify the inputs, configuration values, and classpath/dependency setup related to this operation, then retry.

Example fix

Correct the condition described ("User-defined object the reported value (the reported value) contains non-serializable field the reported value = the reported value") and rerun the job or command.

When it happens

Trigger: Triggered at runtime when the operation fails because: User-defined object the reported value (the reported value) contains non-serializable field the reported value = the reported value.

Common situations: Commonly caused by misconfiguration, missing dependencies or files, unsupported types or operations, or invalid user input leading to: User-defined object the reported value (the reported value) contains non-serializable field the reported value = the reported value.


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/7817095ee274cd01. Report an issue: GitHub.