{"record":{"id":"adbb47afcbf0b254","repo":"oracle/graal","slug":"unsupportedtypeexception-serialization-is-not-supp","errorCode":null,"errorMessage":"UnsupportedTypeException serialization is not supported.","messagePattern":"UnsupportedTypeException serialization is not supported\\.","errorType":"exception","errorClass":"NotSerializableException","httpStatus":null,"severity":"error","filePath":"espresso/src/com.oracle.truffle.espresso.polyglot/src/com/oracle/truffle/espresso/polyglot/UnsupportedTypeException.java","lineNumber":118,"sourceCode":"     * supported.\n     * <p>\n     * In addition a cause may be provided. The cause should only be set if the guest language code\n     * caused this problem. An example for this is a language specific proxy mechanism that invokes\n     * guest language code to describe an object. If the guest language code fails to execute and\n     * this interop exception is a valid interpretation of the error, then the error should be\n     * provided as cause.\n     *\n     * @param cause the guest language exception that caused the error.\n     * \n     * @since 21.0\n     */\n    public static UnsupportedTypeException create(Object[] suppliedValues, String hint, Throwable cause) {\n        return new UnsupportedTypeException(hint, suppliedValues, cause);\n    }\n\n    @SuppressWarnings({\"static-method\", \"unused\"})\n    private void writeObject(ObjectOutputStream outputStream) throws IOException {\n        throw new NotSerializableException(UnsupportedTypeException.class.getSimpleName() + \" serialization is not supported.\");\n    }\n}\n","sourceCodeStart":100,"sourceCodeEnd":121,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/espresso/src/com.oracle.truffle.espresso.polyglot/src/com/oracle/truffle/espresso/polyglot/UnsupportedTypeException.java#L100-L121","documentation":"UnsupportedTypeException (thrown by Truffle interop when guest values do not match a parameter/accessor type) deliberately blocks Java serialization. Its private writeObject always throws NotSerializableException because the exception carries polyglot value references that cannot be faithfully serialized. Attempting to write such an exception through ObjectOutputStream triggers this failure.","triggerScenarios":"Calling ObjectOutputStream.writeObject on an UnsupportedTypeException (or on a Throwable graph containing one, e.g. serializing a request-scoped exception to a remote node or into a session). Also triggered by frameworks that auto-serialize exceptions (RMI, Spring session, akka serialization, distributed test runners).","commonSituations":"Polyglot/Espresso apps that propagate interop type errors across process boundaries; saving exceptions to disk for later inspection; sending exceptions over a message queue. Works locally, fails only when the exception crosses a serialization boundary.","solutions":["Do not serialize the exception itself; extract and serialize the message string and class name instead.","Before serializing a Throwable chain, walk getCause()/getSuppressed() and replace any UnsupportedTypeException with a plain RuntimeException carrying its message.","If using a framework with pluggable serializers, switch that message type to a string-based serializer.","Log the full exception locally (toString includes the offending values) and ship only the log record."],"exampleFix":"// before\nobjectOutputStream.writeObject(caughtException); // may contain UnsupportedTypeException\n\n// after\nThrowable safe = caughtException;\nif (safe instanceof UnsupportedTypeException ute) {\n    safe = new RuntimeException(ute.getClass().getName() + \": \" + ute.getMessage());\n}\nobjectOutputStream.writeObject(safe);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    out.writeObject(throwable);\n} catch (NotSerializableException e) {\n    out.writeObject(sanitize(throwable)); // replace UnsupportedTypeException in the chain with a plain RuntimeException\n}","preventionTips":["Never serialize polyglot exceptions; log them locally and ship strings.","Walk Throwable chains for polyglot types before any writeObject call.","Configure distributed frameworks to serialize exception metadata (class + message), not the exception object."],"tags":["serialization","polyglot","truffle","espresso","exception"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}