Search before asking
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?
Search before asking
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
Version and environment
Flink Agents: 0.3-SNAPSHOT (current main)
Flink: 1.20.0
Java: JDK 17+
Are you willing to submit a PR?