I found, that IntelliJ Idea with Kotlin 1.3.41 shows invalid result for poll() method of ConcurrentLinkedQueue. It is nullable, however kotlin thinks that not (e.g. code val x = queue.poll(); x.myField = 123; does not fail).
Question: what is better to do with the following bugs? I can create Youtrack issue or PR at github to fix annotations.
@fvasco, please check more detailed example below.
ConcurrentLinkedDeque is platform type. However: do we have any library/tool, which annotates Java Standard Library? If yes, then I’d like to put @Nullable hint there. If there are not such tools - ok.
fun dequeue1(): Int {
val queue = ConcurrentLinkedDeque<String>()
val firstItem = queue.poll() // can be null, according to docs, however hint is with not-null
return firstItem.length
}
fun dequeue2(): Int {
val queue = ConcurrentLinkedDeque<String>()
val firstItem: String? = queue.poll()
return firstItem.length // compilation error, which is correct
}