Skip to content

[Bug] Kryo serialization fails for Event classes with immutable lists on JDK 17+ #673

@avichaym

Description

@avichaym

Search before asking

  • I searched in the issues and found nothing similar.

Description

ChatRequestEvent, ContextRetrievalResponseEvent, and ToolRequestEvent store their List<> constructor arguments by reference. When callers pass an immutable list (List.of(...), Arrays.asList(...), Collections.unmodifiableList(...)), Flink's Kryo serializer fails at runtime with an InaccessibleObjectException because JDK 17+ restricts reflective access to internal fields of java.util.Arrays$ArrayList and similar immutable list implementations.

The failure is non-obvious: the event is constructed successfully, but the job crashes when the first record is serialized/cloned between operators.

How to reproduce

// In any agent action:
ChatMessage msg = new ChatMessage(MessageRole.USER, "hello");
ctx.sendEvent(new ChatRequestEvent("myModel", List.of(msg)));
// ^^^ List.of() produces an immutable list

Run the pipeline on JDK 17+ (the minimum for Flink 1.20). The job fails with:

Caused by: java.lang.reflect.InaccessibleObjectException:
Unable to make field private final java.lang.Object[]
java.util.Arrays$ArrayList.a accessible: module java.base
does not "opens java.util" to unnamed module @...

Expected Behaviour

Events should accept any valid List regardless of mutability. The user should not need to know that Kryo requires mutable lists internally.
Affected Classes

org.apache.flink.agents.api.event.ChatRequestEvent
org.apache.flink.agents.api.event.ContextRetrievalResponseEvent
org.apache.flink.agents.api.event.ToolRequestEvent

Version and environment

Flink Agents: 0.3-SNAPSHOT (current main)
Flink: 1.20.0
Java: JDK 17+

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug[Issue Type] Something isn't working as expected.priority/majorDefault priority of the PR or issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions