Skip to content

Commit

Permalink
Fix NPE when invoke asynchronously use JDKProxy. (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjboy authored May 3, 2018
1 parent 921096d commit 7d54cfe
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.alipay.sofa.rpc.proxy.jdk;

import com.alipay.sofa.rpc.common.utils.ClassUtils;
import com.alipay.sofa.rpc.core.exception.RpcErrorType;
import com.alipay.sofa.rpc.core.exception.SofaRpcException;
import com.alipay.sofa.rpc.core.request.SofaRequest;
Expand Down Expand Up @@ -79,6 +80,9 @@ public Object invoke(Object proxy, Method method, Object[] paramValues)
if (ret instanceof Throwable) {
throw (Throwable) ret;
} else {
if (ret == null) {
return ClassUtils.getDefaultArg(method.getReturnType());
}
return ret;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
*/
package com.alipay.sofa.rpc.codec;

import com.alipay.sofa.rpc.common.RpcConstants;
import com.alipay.sofa.rpc.common.struct.ConcurrentHashSet;
import com.alipay.sofa.rpc.config.ConsumerConfig;
import com.alipay.sofa.rpc.config.ProviderConfig;
import com.alipay.sofa.rpc.config.ServerConfig;
import com.alipay.sofa.rpc.context.RpcInvokeContext;
import com.alipay.sofa.rpc.test.ActivelyDestroyTest;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -55,6 +57,7 @@ public class AllTypeServiceTest extends ActivelyDestroyTest {
public void testAll() {
ServerConfig serverConfig2 = new ServerConfig()
.setPort(22222)
.setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT)
.setDaemon(false);

ProviderConfig<AllTypeService> CProvider = new ProviderConfig<AllTypeService>()
Expand Down Expand Up @@ -184,5 +187,49 @@ public void testAll() {

Assert.assertEquals(obj, helloService.echoSubObj(obj));
Assert.assertEquals(subObj, helloService.echoSubObj(subObj));

{
ConsumerConfig<AllTypeService> aConsumer = new ConsumerConfig<AllTypeService>()
.setInterfaceId(AllTypeService.class.getName())
.setTimeout(50000)
.setSerialization("hessian")
.setRepeatedReferLimit(-1)
.setProxy("javassist")
.setInvokeType(RpcConstants.INVOKER_TYPE_FUTURE)
.setDirectUrl("bolt://127.0.0.1:22222");
AllTypeService helloService2 = aConsumer.refer();
Assert.assertEquals(0, helloService2.echoInt(1));
boolean error = false;
Integer v = null;
try {
v = (Integer) RpcInvokeContext.getContext().getFuture().get();
} catch (Exception e) {
error = true;
}
Assert.assertFalse(error);
Assert.assertTrue(v == 1);
}

{
ConsumerConfig<AllTypeService> aConsumer = new ConsumerConfig<AllTypeService>()
.setInterfaceId(AllTypeService.class.getName())
.setTimeout(50000)
.setSerialization("hessian")
.setRepeatedReferLimit(-1)
.setProxy("jdk")
.setInvokeType(RpcConstants.INVOKER_TYPE_FUTURE)
.setDirectUrl("bolt://127.0.0.1:22222");
AllTypeService helloService2 = aConsumer.refer();
Assert.assertEquals(0, helloService2.echoInt(1));
boolean error = false;
Integer v = null;
try {
v = (Integer) RpcInvokeContext.getContext().getFuture().get();
} catch (Exception e) {
error = true;
}
Assert.assertFalse(error);
Assert.assertTrue(v == 1);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rpc.config.order": 999,
"logger.impl": "com.alipay.sofa.rpc.log.SLF4JLoggerImpl"
}

0 comments on commit 7d54cfe

Please sign in to comment.