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

telnet can't work when parameter has no nullary constructor and some fields is primitive #4007

Closed
fibbery opened this issue May 9, 2019 · 1 comment · Fixed by #4026
Closed
Milestone

Comments

@fibbery
Copy link

fibbery commented May 9, 2019

Environment

  • Dubbo version: 2.6.0
  • Operating System version: macOS 10.14.3
  • Java version: 1.8.0_201

Steps to reproduce this issue

  1. create a class has no nullary constructor and some fields is primitive
public class User implements Serializable {
    private static final long serialVersionUID = -467269449632818122L;
    private int age;
    private String name;
    public User(int age, String name) {
        this.age = age;
        this.name = name;
    }
}
  1. create new method in DemoService
public interface DemoService {
    String sayHello(User user);
}
  1. telnet and invoke this method
invoke sayHello({"age":1,"name":"String","class":"User"})

Expected Result

can invoke successfully

Actual Result

throw exception java.lang.IllegalArgumentException

If there is an exception, please attach the exception trace:

java.lang.IllegalArgumentException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at com.alibaba.dubbo.common.utils.PojoUtils.newInstance(PojoUtils.java:527)
        at com.alibaba.dubbo.common.utils.PojoUtils.realize0(PojoUtils.java:436)
        at com.alibaba.dubbo.common.utils.PojoUtils.realize(PojoUtils.java:196)
        at com.alibaba.dubbo.common.utils.PojoUtils.realize(PojoUtils.java:86)
        at com.alibaba.dubbo.rpc.protocol.dubbo.telnet.InvokeTelnetHandler.telnet(InvokeTelnetHandler.java:138)
        at com.alibaba.dubbo.remoting.telnet.support.TelnetHandlerAdapter.telnet(TelnetHandlerAdapter.java:52)
        at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:181)
        at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:50)
        at com.alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:79)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
@fibbery
Copy link
Author

fibbery commented May 9, 2019

should init primitive before new instance
com.alibaba.dubbo.common.utils.PojoUtils#newInstance:L527
pseudo code like this

Class<?>[] parameterTypes = constructor.getParameterTypes();
Object[] parameters = new Object[parameterTypes.length];
for (int i = 0; i < parameterTypes.length; i++) {
    if (parameterTypes[i].isPrimitive()) {
        // init primitive type 
        parameters[i] = getPrimitiveDefaultValue(parameterTypes[i]);
    }
}
return constructor.newInstance(parameters);

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

Successfully merging a pull request may close this issue.

2 participants