Kotlin 可完成。然后结果为;另一个为空;

Kotlin 可完成。然后结果为;另一个为空;,kotlin,rx-java2,Kotlin,Rx Java2,我有以下代码: fun edit(note: Note): Completable = getValidationCompletable(note).andThen(repository.insertOrUpdate(note)) private fun getValidationCompletable(note: Note): Completable { return if (!note.isValidForEdit()) { Completable.error(Il

我有以下代码:

fun edit(note: Note): Completable = getValidationCompletable(note).andThen(repository.insertOrUpdate(note))

private fun getValidationCompletable(note: Note): Completable {
    return if (!note.isValidForEdit()) {
        Completable.error(IllegalArgumentException("note failed validation before edit"))
    } else {
        Completable.complete()
    }
}
如果
note.isValidForEdit()
返回false,我会得到以下结果:

java.lang.NullPointerException: other is null

at io.reactivex.internal.functions.ObjectHelper.requireNonNull(ObjectHelper.java:39)
at io.reactivex.Completable.concatWith(Completable.java:1040)
at io.reactivex.Completable.andThen(Completable.java:908)

有人能解释一下吗?

这似乎已经解决了,但为了解决问题,concatWith(
repository.insertOrUpdate(注意)
)的参数不能为空

有趣的是,ReactiveX似乎有自己的
ObjectHelper.requirennoull
函数,但没有使用任何类型的
NotNull
注释对参数进行注释,因此
Kotlin
编译器无法在编译时检查可空性


在一个问题中建议这个可能是值得的。

存储库。insertOrUpdate(注意)
null
?你是对的,这是一个多么愚蠢的错误!我认为我甚至不应该关心在单元测试中设置第二个Completable,因为第一个会导致错误。错了!谢谢你的帮助!我不确定它有多全面,或者这是否解决了您的问题,但在RxJava中添加了Kotlin扩展-如果您还没有这样做的话,可能值得一看。我将看一看,并可能开始使用RxKotlin而不是RxJava。我的应用程序是100%Kotlin