https://kotlinlang.org logo
Title
d

David Stolarsky

05/15/2019, 4:56 AM
why do I sometimes get a runtime exception due to a non optional value being null? at least when interacting with Android platform APIs. does this mean the platform API is not correctly annotated for consumption in Kotlin?
g

gildor

05/15/2019, 5:00 AM
probably you passed null from Java or have some reflections that create nullable values. Anyway hard to say something particular without details
d

David Stolarsky

05/15/2019, 5:01 AM
c.getString(c.getColumnIndex(StructuredPostal.STREET))
apparently that returned
null
.. i just wish i would get a compile error instead of a runtime error
g

gildor

05/15/2019, 5:02 AM
this is Java API, there is no nullability information
d

David Stolarsky

05/15/2019, 5:02 AM
so shouldn't it be a compile error to assign that to a non optional value?
g

gildor

05/15/2019, 5:02 AM
at least until those functions annotated with Nullable/NonNull
no, it’s a very long story whym, but it’s called platform types
so if Java API is not annotated, it concidered as platform type and maybe used as nullable and non-nullable
d

David Stolarsky

05/15/2019, 5:04 AM
got it
i wonder if there is a linter option that could turn these into compile errors
g

gildor

05/15/2019, 5:05 AM
there is no such option
d

David Stolarsky

05/15/2019, 5:06 AM
ok
o

obobo

05/15/2019, 4:20 PM
for what it's worth there's an inspection for
Function or property has a platform type
which you could set to error (seems to default to weak warning)
g

gildor

05/15/2019, 11:28 PM
It wouldn't be reported for David's usecase, because platform type passed as argument to another platform type, so there is no warning. You see this warning only when expose it in Kotlin API
👍 1