Skip to content

Unnecessary caught ClassCastException due to incorrect instance check #1992

Closed
@fluidsonic

Description

@fluidsonic

While debugging with exception breakpoints I get a lot of internally caught exceptions like this:

ClassCastException: class io.ktor.server.netty.EventLoopGroupProxy cannot be cast
to class java.util.concurrent.ScheduledThreadPoolExecutor

In the following code the executor is cast to ScheduledExecutorService but the reflected Method requires a ScheduledThreadPoolExecutor.

Looks like a bug to me.

private val REMOVE_FUTURE_ON_CANCEL: Method? = try {
ScheduledThreadPoolExecutor::class.java.getMethod("setRemoveOnCancelPolicy", Boolean::class.java)
} catch (e: Throwable) {
null
}
@Suppress("NAME_SHADOWING")
internal fun removeFutureOnCancel(executor: Executor): Boolean {
try {
val executor = executor as? ScheduledExecutorService ?: return false
(REMOVE_FUTURE_ON_CANCEL ?: return false).invoke(executor, true)
return true
} catch (e: Throwable) {
return true
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions