In particular, with "org.elasticsearch" % "elasticsearch" % "2.4.x"
(it works with later versions from ElasticSearch, where it ActionRequest
no longer takes the type of parameter, but we cannot update it yet!).
The Java method we are trying to override is defined as follows ( source ):
protected <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void doExecute(Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) {
in().execute(action, request, listener);
}
A naive attempt to redefine it ...
import org.elasticsearch.action._
import org.elasticsearch.client.{Client, FilterClient}
class DemoFilterClient(underlyingClient: Client) extends FilterClient(underlyingClient) {
override def doExecute[
Request <: ActionRequest[_],
Response <: ActionResponse,
RequestBuilder <: ActionRequestBuilder[Request, Response, RequestBuilder]
](
action: Action[Request, Response, RequestBuilder],
request: Request,
listener: ActionListener[Response]
) = super.doExecute(action, request, listener)
}
... failed in all versions of Scala that we tried (2.11.11, 2.11.12 and 2.12). 4):
[info] Compiling 1 Scala source to /home/roberto/development/elasticsearch-scala-client-test/target/scala-2.11/classes ...
[error] /home/roberto/development/elasticsearch-scala-client-test/src/main/scala/com/gu/DemoFilterClient.scala:7:101: type arguments [Request,Response,RequestBuilder] do not conform to class ActionRequestBuilder type parameter bounds [Request <: org.elasticsearch.action.ActionRequest[_ <: org.elasticsearch.action.ActionRequest[_ <: org.elasticsearch.action.ActionRequest[_ <: AnyRef]]],Response <: org.elasticsearch.action.ActionResponse,RequestBuilder <: org.elasticsearch.action.ActionRequestBuilder[Request,Response,RequestBuilder]]
[error] override def doExecute[Request <: ActionRequest[_], Response <: ActionResponse, RequestBuilder <: ActionRequestBuilder[Request, Response, RequestBuilder]](action: Action[Request, Response, RequestBuilder], request: Request, listener: ActionListener[Response]) = super.doExecute(action, request, listener)
[error] ^
[error] one error found
To more clearly state this compiler error:
type arguments
[Request,Response,RequestBuilder]
do not conform to class ActionRequestBuilder type parameter bounds
[
Request <:
org.elasticsearch.action.ActionRequest[_ <:
org.elasticsearch.action.ActionRequest[_ <:
org.elasticsearch.action.ActionRequest[_ <: AnyRef]]],
Response <: org.elasticsearch.action.ActionResponse,
RequestBuilder <: org.elasticsearch.action.ActionRequestBuilder[Request,Response,RequestBuilder]
]
Please note that an amazing recursive declaration is in type Request
!
sbt, https://github.com/guardian/elasticsearch-scala-client-test