Play 2.5 error - CompletionStage<WSResponse> cannot be converted to F.Promise<WSResponse>

1k Views Asked by At

Hoping someone can help. I'm trying to upgrade from Play 2.4 to 2.5. After upgrading, I'm getting errors in the JavaController class. One of the errors show

[error] /Play-2-JS-2.5/app/controllers/JavaController.java:87: java.util.concurrent.CompletionStage cannot be converted to play.libs.F.Promise [error] WS.url("http://example.com").get()

It looks as though perhaps WSReponse might have been deprecated when going to 2.5. I tried to replace F.Promise with CompletionStage here on line 87 https://github.com/btgrant-76/Play-2-Java-Scala-Java-8-Async-Comparison/blob/6a85cf31cfb804ef20bacf8e14d30ce46cc9307c/app/controllers/JavaController.java#L87 but get the same error. I've been googling for quite sometime and found topics around Dependency Injection however, there aren't any examples. Any examples and/or where to go to from here would be wonderful.

1

There are 1 best solutions below

4
Steve Chaloner On BEST ANSWER

If you replaced

final F.Promise<WSResponse> responsePromise = WS.url("http://example.com").get();

with

final CompletionStage<WSResponse> responsePromise = WS.url("http://example.com").get();

and still get the same error, then things to check include:

  1. Are you saving the source code before you recompile? If F.Promise is mentioned in the error message but doesn't appear in the code, that's fishy. In Play 2.5, WSResponse.get has the signature java.util.concurrent.CompletionStage<WSResponse> get() so F.Promise shouldn't be coming from there. See the javadoc for reference.

  2. Check the versions of Play jars you have in your classpath. If you're converting from 2.4 to 2.5, it's possible you still have dependencies which pull in Play 2.4 jars as transitive dependencies. If you're not using an IDE, which should display the classpath for you, use a tool like this one to view dependencies.

EDIT

Based on the error message given in your comment, you're importing the wrong WSResponse class because you're mixing the Java and Scala APIs. It looks like you're importing play.api.libs.ws.WSResp‌​onse instead of play.libs.ws.WSResp‌​onse (note the api part of the package, this denotes the Scala API).