|
21 | 21 | import java.util.List;
|
22 | 22 | import java.util.Set;
|
23 | 23 | import java.util.concurrent.CompletableFuture;
|
24 |
| -import java.util.concurrent.CompletionException; |
25 | 24 | import java.util.function.Function;
|
26 | 25 | import java.util.logging.Level;
|
27 | 26 | import java.util.logging.Logger;
|
@@ -60,14 +59,20 @@ protected void recursiveFindRpcMethods(Object current, Set<Class<?>> visited, Se
|
60 | 59 | AnnotationUtil.findRpcMethods(current.getClass(), visited, (methodInfo) -> {
|
61 | 60 | @SuppressWarnings("unchecked")
|
62 | 61 | Function<Object, CompletableFuture<Object>> handler = (arg) -> {
|
| 62 | + Method method = methodInfo.method; |
| 63 | + Object[] arguments = this.getArguments(method, arg); |
63 | 64 | try {
|
64 |
| - Method method = methodInfo.method; |
65 |
| - Object[] arguments = this.getArguments(method, arg); |
66 | 65 | return (CompletableFuture<Object>) method.invoke(current, arguments);
|
67 | 66 | } catch (InvocationTargetException e) {
|
68 |
| - throw new CompletionException(e.getCause()); |
| 67 | + Throwable cause = e.getCause(); |
| 68 | + if (cause instanceof RuntimeException) { |
| 69 | + throw (RuntimeException) cause; |
| 70 | + } else if (cause instanceof Error) { |
| 71 | + throw (Error) cause; |
| 72 | + } |
| 73 | + throw new IllegalStateException("An unexpected exception occurred while executing jsonrpc method " + method, cause); |
69 | 74 | } catch (IllegalAccessException e) {
|
70 |
| - throw new CompletionException(e); |
| 75 | + throw new IllegalStateException("Inaccessible jsonrpc method: " + method, e); |
71 | 76 | }
|
72 | 77 | };
|
73 | 78 | if (methodHandlers.put(methodInfo.name, handler) != null) {
|
@@ -179,5 +184,4 @@ public void notify(String method, Object parameter) {
|
179 | 184 | protected boolean isOptionalMethod(String method) {
|
180 | 185 | return method != null && method.startsWith("$/");
|
181 | 186 | }
|
182 |
| - |
183 | 187 | }
|
0 commit comments