Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Says "the method invoking await must return a CompletableFuture" but it does already #34

Open
DidierLoiseau opened this issue Mar 8, 2019 · 4 comments
Labels

Comments

@DidierLoiseau
Copy link

If you forget to instrument the code, the wrong warning message is printed:

WARN com.ea.async.Async - Warning: Illegal call to await, the method invoking await must return a CompletableFuture

instead of

Warning: Illegal call to await, static { Async.init(); } must be added to the main program class and the method invoking await must return a CompletableFuture

As shown by the following simple example:

import java.util.concurrent.CompletableFuture;

import com.ea.async.Async;

public class EAsyncTest {

	static CompletableFuture<String> convert(CompletableFuture<?> future) {
		Object result = Async.await(future);
		return CompletableFuture.completedFuture(result.toString());
	}

	public static void main(String[] args) {
		convert(new CompletableFuture<>());
	}
}

This is because calling InitializeAsync.isRunning() triggers the class initialization, and only enters that method once isRunning = true. The only ways to have isRunning() returning false is if either the initialization crashes or if called from multiple threads.

In addition, I think it would be better to throw an exception than calling join(). In the above example this causes a deadlock, and you don't know which method it is referring to.

@JoeHegarty JoeHegarty added the bug label Mar 19, 2019
@TryingToImprove
Copy link

It also seems like if you have instrumented your code it will always give:

WARN com.ea.async.Async - Warning: Illegal call to await, the method invoking await must return a CompletableFuture

I am not sure if the else part should have been something like below instead

        if (!InitializeAsync.isRunning()) {
            warning = "Warning: Illegal call to await, static { Async.init(); } must be added to the main program class and the method invoking await must return a CompletableFuture";
        } else if (!(future instanceof CompletableFuture)) {
            warning = "Warning: Illegal call to await, the method invoking await must return a CompletableFuture";
        }

@DidierLoiseau
Copy link
Author

@TryingToImprove if you have properly instrumented your code, the call to await() is removed, so you shouldn't get a warning.

@spyro2000
Copy link

Getting this warning, too, despite initialized directly in the main method with Await.init().

@jpines-vi
Copy link

I am seeing this, too, even while my code (under test) runs as expected. Would a reproducer be helpful?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants