Closed
Description
Reproduction steps
Scala version: 2.12.17
Works in 2.13
def afterCompletionStage[T](duration: FiniteDuration, using: Scheduler)(value: => CompletionStage[T])(
implicit ec: ExecutionContext): CompletionStage[T] =
if (duration.isFinite && duration.length < 1) {
try value
catch { case NonFatal(t) => Futures.failedCompletionStage(t) }
} else {
val p = new CompletableFuture[T]
using.scheduleOnce(duration) {
try {
val future = value
future.handle(new BiFunction[T, Throwable, Unit] {
override def apply(t: T, ex: Throwable): Unit = {
if (t != null) p.complete(t)
if (ex != null) p.completeExceptionally(ex)
}
})
} catch {
case NonFatal(ex) => p.completeExceptionally(ex)
}
}
p
}
Problem
[error] C:\Users\hepin\IdeaProjects\akka\akka-actor\src\main\scala\akka\pattern\FutureTimeoutSupport.scala:71:18: no type parameters for method handle: (x$1: java.util.function.BiFunction[_ >: T, Throwable, _ <: U])java.util.concurrent.CompletionStage[U] exist so that it can be applied to arguments (java.util.function.BiFunction[T,Throwable,Unit])
[error] --- because ---
[error] argument expression's type is not compatible with formal parameter type;
[error] found : java.util.function.BiFunction[T,Throwable,Unit]
[error] required: java.util.function.BiFunction[_ >: T, Throwable, _ <: ?U]
[error] Note: T <: Any, but Java-defined trait BiFunction is invariant in type T.
[error] You may wish to investigate a wildcard type such as `_ <: Any`. (SLS 3.2.10)
[error] future.handle(new BiFunction[T, Throwable, Unit] {
[error] ^
[error] C:\Users\hepin\IdeaProjects\akka\akka-actor\src\main\scala\akka\pattern\FutureTimeoutSupport.scala:71:25: type mismatch;
[error] found : java.util.function.BiFunction[T,Throwable,Unit]
[error] required: java.util.function.BiFunction[_ >: T, Throwable, _ <: U]
[error] future.handle(new BiFunction[T, Throwable, Unit] {
[error] ^
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 16 s, completed 2023-4-20 23:43:53
[IJ]
Metadata
Metadata
Assignees
Labels
No labels