diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java index 0872ebaaecb6..df5a12a03f14 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java @@ -294,7 +294,18 @@ protected void encodeRequestData(Channel channel, ObjectOutput out, Object data, Object[] args = inv.getArguments(); if (args != null) { for (int i = 0; i < args.length; i++) { - out.writeObject(callbackServiceCodec.encodeInvocationArgument(channel, inv, i)); + Object arg = callbackServiceCodec.encodeInvocationArgument(channel, inv, i); + try { + out.writeObject(arg); + } catch (IOException e) { + Throwable cause = e.getCause() != null ? e.getCause().getCause() : null; + if (cause instanceof IllegalArgumentException + && cause.getMessage() != null + && cause.getMessage().contains("has not implement Serializable")) { + throw new IOException(arg.getClass().getName() + " must implement java.io.Serializable", e); + } + throw e; + } } } out.writeAttachments(inv.getObjectAttachments()); @@ -313,7 +324,17 @@ protected void encodeResponseData(Channel channel, ObjectOutput out, Object data out.writeByte(attach ? RESPONSE_NULL_VALUE_WITH_ATTACHMENTS : RESPONSE_NULL_VALUE); } else { out.writeByte(attach ? RESPONSE_VALUE_WITH_ATTACHMENTS : RESPONSE_VALUE); - out.writeObject(ret); + try { + out.writeObject(ret); + } catch (IOException e) { + Throwable cause = e.getCause() != null ? e.getCause().getCause() : null; + if (cause instanceof IllegalArgumentException + && cause.getMessage() != null + && cause.getMessage().contains("has not implement Serializable")) { + throw new IOException(ret.getClass().getName() + " must implement java.io.Serializable", e); + } + throw e; + } } } else { out.writeByte(attach ? RESPONSE_WITH_EXCEPTION_WITH_ATTACHMENTS : RESPONSE_WITH_EXCEPTION); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocolTest.java b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocolTest.java index adfb29a10f77..f7d9fcec5b5d 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocolTest.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocolTest.java @@ -234,7 +234,6 @@ void testPerm() { } @Test - @Disabled public void testNonSerializedParameter() { DemoService service = new DemoServiceImpl(); int port = NetUtils.getAvailablePort(); @@ -258,7 +257,6 @@ public void testNonSerializedParameter() { } @Test - @Disabled public void testReturnNonSerialized() { DemoService service = new DemoServiceImpl(); int port = NetUtils.getAvailablePort();