Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassNotFoundException is not serializable for Adoptium jdk 17 #78

Open
temppost2 opened this issue Nov 8, 2023 · 1 comment
Open

Comments

@temppost2
Copy link

When RpcSession fails with deserialization of incoming request, in particular, when some method or class is missing on server side, it throws ClassNotFoundException and tries to RpcSession#writeResponse with this exception. But RpcSession#writeResponse fails too, because ClassNotFoundException cannot be serialized.

It leads to the following exception on server side:

16:23:18,095|W|[NIO Selector #2] Local type not found: EchoService$Message
16:23:18,117|E|[NIO Selector #2] Cannot process session from 127.0.0.1
java.io.IOException: writeObject() is not fully supported. See implementation notes.
	at one.nio.serial.gen.NullObjectOutputStream.unsupported(NullObjectOutputStream.java:159)
	at one.nio.serial.gen.NullObjectOutputStream.putFields(NullObjectOutputStream.java:50)
	at java.base/java.lang.ClassNotFoundException.writeObject(ClassNotFoundException.java:144)
	at sun.reflect.Delegate0_ClassNotFoundException.calcSize(Unknown Source)
	at one.nio.serial.GeneratedSerializer.calcSize(GeneratedSerializer.java:116)
	at one.nio.serial.CalcSizeStream.writeObject(CalcSizeStream.java:129)
	at one.nio.rpc.RpcSession.writeResponse(RpcSession.java:196)
	at one.nio.rpc.RpcSession.handleDeserializationException(RpcSession.java:250)
	at one.nio.rpc.RpcSession.processRead(RpcSession.java:108)
	at one.nio.net.Session.process(Session.java:222)
	at one.nio.server.SelectorThread.run(SelectorThread.java:70)

  • Both client and server runs on openjdk version "17.0.9" 2023-10-17
  • Checked on one-nio 1.6.1 and 1.7.1
@temppost2
Copy link
Author

How to reproduce.
Server-side code:

import one.nio.rpc.RpcServer;
import one.nio.server.ServerConfig;

import java.io.IOException;

public class EchoServer implements EchoService {

    @Override
    public byte[] echo(byte[] message) {
        return message;
    }

    public static void main(String[] args) throws IOException {
        ServerConfig config = ServerConfig.from("127.0.0.1:12500");
        EchoService service = new EchoServer();
        new RpcServer<>(config, service).start();
        System.out.println("Server started");
    }
}

interface EchoService {
    byte[] echo(byte[] message);
}

Client-side code:

import one.nio.net.ConnectionString;
import one.nio.rpc.RpcClient;

import java.io.Serializable;
import java.lang.reflect.Proxy;

public class EchoClient {
    public static void main(String[] args) {
        ConnectionString conn = new ConnectionString("127.0.0.1:12500");
        EchoService client = (EchoService) Proxy.newProxyInstance(
            EchoClient.class.getClassLoader(),
            new Class[]{EchoService.class},
            new RpcClient(conn));

        client.echo(new EchoService.Message(1, "abc"));
    }
}

interface EchoService {
    Message echo(Message msg);

    class Message implements Serializable {
        private int id;
        private String content;

        public Message(int id, String content) {
            this.id = id;
            this.content = content;
        }
    }
}

Just launch server-side on jdk 17, then launch client-side on jdk 17

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

No branches or pull requests

2 participants