"Value is never used as Publisher" - what does this mean?

Answered

I've started seeing warnings "Value is never used as Publisher ", for example from this code:

override val locationObserver: Observable<Location> = Observable.create {
emitter = it
}

I have no idea what this means. The value certainly does get used elsewhere. Now I could just disable the inspection but I would like to know what it means before doing that.

 

0
3 comments

May you share entire code sample? 

Inspection description could be found under Settings (Preferences on macOS) | Editor | Inspections | Reactive Streams | Common | Unused publisherhttps://i.imgur.com/Nw0Kubn.png

at the same place, you can disable it. 

0
Avatar
Permanently deleted user

Here is a complete sample. So from the description this is actually a bug (false positive) - the Provider *is* subscribed to.

@Test
fun demo() {
lateinit var emitter: ObservableEmitter<Int>
val provider = object {
val locationObserver: Observable<Int> = Observable.create {
emitter = it
}
}

provider.locationObserver.subscribe {
println(it)
}

emitter.onNext(1)
emitter.onComplete()
}
0

Will be fixed in IntelliJ IDEA 2020.3. We are working on backporting to 2020.2: https://youtrack.jetbrains.com/issue/IDEA-245639

0

Please sign in to leave a comment.