Skip to content

Commit

Permalink
Fix consumer exception missing when void method from provider is call…
Browse files Browse the repository at this point in the history
…ed with exception.
  • Loading branch information
leizhiyuan authored and JervyShi committed Jun 28, 2018
1 parent 42e63bd commit 8a8fff4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,19 @@ private void createMethod(Class<?> interfaceClass, List<String> fieldList, List<
".SERVER_UNDECLARED_ERROR," + " response.getErrorMsg());");
sb.append("}");

sb.append("Object ret = response.getAppResponse();");
sb.append("if (ret instanceof Throwable) {");
sb.append(" throw (Throwable) ret;");
sb.append("} else {");
if (returnType.equals(void.class)) {
sb.append(" return;");
} else {
sb.append("Object ret = response.getAppResponse();");
sb.append("if (ret instanceof Throwable) {");
sb.append(" throw (Throwable) ret;");
sb.append("} else {");
sb.append(" return " + asArgument(returnType, "ret") + ";");
sb.append("}");
sb.append(" return " + asArgument(returnType, "ret") + ";");
}
sb.append("}");

sb.append("}");

resultList.add(sb.toString());
sb.delete(0, sb.length());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,12 @@ public void testAll() {
Assert.assertTrue(e instanceof TestException);
Assert.assertEquals(e.getMessage(), "TestException");
}

try {
service.throwDeclaredExceptionWithoutReturn();
} catch (Throwable e) {
Assert.assertTrue(e instanceof TestException);
Assert.assertEquals(e.getMessage(), "DeclaredExceptionWithoutReturn");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public interface TestExceptionService {
public String throwSofaException() throws SofaRpcException;

public String throwDeclaredException() throws TestException;

public void throwDeclaredExceptionWithoutReturn() throws TestException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public String throwSofaException() throws SofaRpcException {
public String throwDeclaredException() throws TestException {
throw new TestException("TestException");
}

@Override
public void throwDeclaredExceptionWithoutReturn() throws TestException {
throw new TestException("DeclaredExceptionWithoutReturn");
}
}

0 comments on commit 8a8fff4

Please sign in to comment.