Vitali Plagov
10/18/2021, 8:24 AMdata class ProfileItem(val id: String, val item: Item)
data class Item (val code: String)
When I get a List<ProfileItem>
from the 3rd service (can’t control it), the item
field for some elements in the list might be null
. And when I do
val eligibleCodes = service.gerProfileItems().filter { it.item.code in approvedCodes }
it fails with NPE, so I had to do filter { it.item != null }
once I got the list. And IntelliJ complains about this filtering saying that this condition is always true.
Is it an issue with the IntelliJ IDEA’s inspection? Or I should do this operation differently?Jakub
10/18/2021, 8:34 AMItem?
in your class if null
is an expected value for the field. Idea is right to complain that your code is not saying it is nullable.Vitali Plagov
10/18/2021, 8:39 AMTobias Berger
10/18/2021, 9:24 AMStephan Schroeder
10/19/2021, 6:41 AMval itemsOrNulls: List<ProfileItem?> = service.gerProfileItems()
val items: List<ProfileItem> = itemsOrNulls.filterNotNull()