diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/GenericEndpoint.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/GenericEndpoint.java index 9bbe16ad9..8cfa43d09 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/GenericEndpoint.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/GenericEndpoint.java @@ -21,7 +21,6 @@ import java.util.List; import java.util.Set; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionException; import java.util.function.Function; import java.util.logging.Level; import java.util.logging.Logger; @@ -60,14 +59,20 @@ protected void recursiveFindRpcMethods(Object current, Set> visited, Se AnnotationUtil.findRpcMethods(current.getClass(), visited, (methodInfo) -> { @SuppressWarnings("unchecked") Function> handler = (arg) -> { + Method method = methodInfo.method; + Object[] arguments = this.getArguments(method, arg); try { - Method method = methodInfo.method; - Object[] arguments = this.getArguments(method, arg); return (CompletableFuture) method.invoke(current, arguments); } catch (InvocationTargetException e) { - throw new CompletionException(e.getCause()); + Throwable cause = e.getCause(); + if (cause instanceof RuntimeException) { + throw (RuntimeException) cause; + } else if (cause instanceof Error) { + throw (Error) cause; + } + throw new IllegalStateException("An unexpected exception occurred while executing jsonrpc method " + method, cause); } catch (IllegalAccessException e) { - throw new CompletionException(e); + throw new IllegalStateException("Inaccessible jsonrpc method: " + method, e); } }; if (methodHandlers.put(methodInfo.name, handler) != null) { @@ -179,5 +184,4 @@ public void notify(String method, Object parameter) { protected boolean isOptionalMethod(String method) { return method != null && method.startsWith("$/"); } - }