Skip to content

Text renderer stores the raw CharSequence in the mime bundle — non-String implementations render as object internals or fail with JsonIOException #130

Description

@paulk-asert

Version: 1.0-a8 JDK 17.

Text.renderCharSequence puts the CharSequence object itself into the DisplayData bundle for every requested mime type:

context.renderIfRequested(PLAIN, () -> data);   // raw object, not data.toString()

Since the kernel returns real result objects (via the takeResult mechanism), the stored object is later serialized by Gson when the execute_result message is sent — and Gson only produces sensible output for types it has adapters for. Observed results for a cell whose value is a CharSequence:

Result value What the frontend receives
String, StringBuilder, StringBuffer correct text (Gson happens to ship adapters)
java.nio.CharBuffer.wrap("hello") JsonIOException: Failed making field 'java.nio.StringCharBuffer#str' accessible… during message serialization
any library/user CharSequence (e.g. commons-text TextStringBuilder) reflective field dump, e.g. {"s":"hello"}
Groovy GString (via a jjava-jupyter-based Groovy kernel) {"strings":[…], "values":[…], "frozen":false, …}

Standalone repro (no notebook needed):

Renderer renderer = new Renderer();
Text.registerAll(renderer);
Object stored = renderer.render(java.nio.CharBuffer.wrap("hello")).getData(MIMEType.TEXT_PLAIN);
new com.google.gson.Gson().toJson(stored);   // JsonIOException; a custom CharSequence yields {"s":"hello"}

Suggested fix: materialize the text at render time — renderIfRequested(PLAIN, () -> String.valueOf(data)) (likewise for the other supported mimes in renderCharSequence). Happy to send a PR.

Context: found while building groovy-jupyter, a Groovy kernel on top of the jjava-jupyter base module (where every GString result hits this).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions