Why I get "incompatible types" when trying to use the accumulator recover method?

Sorry for the stupid question, but I have been unable to cope with it for a long time and despaired of figuring it out on my own.

I am trying to write a BodyParser that returns a source of strings:

@Override
    public Accumulator<ByteString, F.Either<Result, Source<String, ?>>> apply(Http.RequestHeader request) {
    Flow<ByteString, String, ?> flow = Flow.<ByteString>create()
        .via(Framing.delimiter(ByteString.fromString("\n"), 256, FramingTruncation.ALLOW))
        .map(ByteString::utf8String)
        // other operations
        .limit(100);

    return Accumulator.<String>source()
        .through(flow)
        .map(F.Either::Right, executor);
}

It works as I intended. But if I try to add error handling using the recover method

return Accumulator.<String>source()
    .through(flow)
    .map(F.Either::Right, executor)
    .recover(throwable -> F.Either.Left(Results.internalServerError(throwable.getMessage())), executor);

the code stops compiling with an error

incompatible types: play.libs.streams.Accumulator<akka.util.ByteString,play.libs.F.Either<java.lang.Object,akka.stream.javadsl.Source<java.lang.String,capture#1 of ?>>> cannot be converted to play.libs.streams.Accumulator<akka.util.ByteString,play.libs.F.Either<play.mvc.Result,akka.stream.javadsl.Source<java.lang.String,?>>>

What am I doing wrong? :frowning:

The compiler can’t infer that the Accumulator returned by map is an Accumulator<ByteString, Source<String,?>>. You can help the compiler by specifying the type of Either you expect:

.map(v -> F.Either.<Result, Source<String, ?>>Right(v), executor)