Skip to content

Commit

Permalink
Polish /apache#3429 : Fix The NPE issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mercyblitz committed Mar 15, 2019
1 parent 1d6845c commit e402e38
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Collection;
Expand Down Expand Up @@ -155,7 +156,18 @@ private ReferenceBeanInvocationHandler(ReferenceBean referenceBean) {

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return method.invoke(bean, args);
Object result = null;
try {
if (bean == null) { // If the bean is not initialized, invoke init()
// issue: https://github.com/apache/incubator-dubbo/issues/3429
init();
}
result = method.invoke(bean, args);
} catch (InvocationTargetException e) {
// re-throws the actual Exception.
throw e.getTargetException();
}
return result;
}

private void init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public Map<String, String> convert(String[] source) {
Assert.assertEquals("dubbo://localhost:12345", referenceBean.getUrl());
Assert.assertEquals("client", referenceBean.getClient());
Assert.assertEquals(true, referenceBean.isGeneric());
Assert.assertEquals(true, referenceBean.isInjvm());
Assert.assertNull(referenceBean.isInjvm());
Assert.assertEquals(false, referenceBean.isCheck());
Assert.assertEquals(true, referenceBean.isInit());
Assert.assertEquals(true, referenceBean.getLazy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void testBuild() throws Exception {
Assert.assertEquals("dubbo://localhost:12345", referenceBean.getUrl());
Assert.assertEquals("client", referenceBean.getClient());
Assert.assertEquals(true, referenceBean.isGeneric());
Assert.assertEquals(true, referenceBean.isInjvm());
Assert.assertNull(referenceBean.isInjvm());
Assert.assertEquals(false, referenceBean.isCheck());
Assert.assertEquals(null, referenceBean.isInit());
Assert.assertEquals(true, referenceBean.getLazy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ public String sayName(String name) {

@Override
public Box getBox() {
return new Box() {
@Override
public String getName() {
return "MyBox";
}
};
throw new UnsupportedOperationException("For Purposes!");
}
}

0 comments on commit e402e38

Please sign in to comment.