public CompletableFuture invokeMethodAsync()

in src/main/java/com/jetbrains/jdi/InvokableTypeImpl.java [149:186]


    public CompletableFuture<Value> invokeMethodAsync(ThreadReference threadIntf, Method methodIntf,
                              List<? extends Value> origArguments, int options)
            throws InvalidTypeException,
            ClassNotLoadedException,
            IncompatibleThreadStateException,
            InvocationException {
        validateMirror(threadIntf);
        validateMirror(methodIntf);
        validateMirrorsOrNulls(origArguments);
        MethodImpl method = (MethodImpl) methodIntf;
        ThreadReferenceImpl thread = (ThreadReferenceImpl) threadIntf;
        validateMethodInvocation(method);
        List<? extends Value> arguments = method.validateAndPrepareArgumentsForInvoke(origArguments, options);
        ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
        PacketStream stream = sendInvokeCommand(thread, method, args, options);
        return readReply(stream)
                .exceptionally(throwable -> {
                    throwable = AsyncUtils.unwrap(throwable);
                    if (throwable instanceof IllegalThreadStateException) {
                        throw new CompletionException(new IncompatibleThreadStateException());
                    }
                    throw (RuntimeException) throwable;
                })
                .thenApply(ret -> {
                    /*
                     * There is an implict VM-wide suspend at the conclusion
                     * of a normal (non-single-threaded) method invoke
                     */
                    if ((options & ClassType.INVOKE_SINGLE_THREADED) == 0) {
                        vm.notifySuspend();
                    }
                    if (ret.getException() != null) {
                        throw new CompletionException(new InvocationException(ret.getException()));
                    } else {
                        return ret.getResult();
                    }
                });
    }