Recently, I used the RxJava method
Completable.doOnEvent
, which takes a lambda `(Throwable?) -> Unit`:
myCompletable.doOnEvent { doSomething() }
However, this started throwing exceptions. As it is a Java method, Kotlin automatically regarded
it
as
Throwable!
and therefore
Throwable
, and as soon as the lambda was called with a null value, it did a null check and threw a NPE, even though it was verifying a value that went completely unused.
As the only reason Kotlin automatically treats
Throwable!
as
Throwable
here is for convenience, could it recognize in this case that the parameter is entirely unused, and therefore not overeagerly perform a null check? The solution to avoid the exception is to specify
{ _: Throwable? -> doSomething() }
, which I'd rather not need to specify, and I'd especially have preferred not to have to deal with the exception in the first place at all.