hi, is there a compiler setting to mark all objects returned by java methods nullable?
e.g. we are using jooq, a library to write type safe sql queries. it has several
fetch
methods, all of which might or might not return a value, depending on what the sql returns.
The compiler doesn;t recognize it's nullable and so we are always in danger to produce NPEs...
n
nfrankel
11/10/2020, 12:47 PM
when itโs returned by java
the type is inferred as
X!
and intellij idea warns you about it
that you should set the return type yourself because it cannot be inferred
either
X
or
X?
g
gildor
11/10/2020, 1:09 PM
Marking ALL return types from java as nullable is not possible, it would make work with many java APIs very unpleasant
The real problem here is that jooq nullable annotation.is not recognized, worth to create an issue
gildor
11/10/2020, 1:17 PM
Are you sure this method is annotated? What is nullable annotation is used?
j
Joe
11/10/2020, 3:15 PM
what version of jooq are you using? he added nullable/notnull annotations in 3.14.x
t
thana
11/10/2020, 3:26 PM
ah so if there is NO annotation the type is noch recognized nullable?
g
gildor
11/10/2020, 3:47 PM
No, if there is no annotation, it will be platform type, as Nicolas wrote above
gildor
11/10/2020, 3:49 PM
As I see jooq uses org.jetbrains.annotations, which are supported by Kotlin
So if something is not annotated, way to go is to create an issue on jooq repo, when nullability annotation will be added it will be recognized by Kotlin
t
thana
11/10/2020, 5:02 PM
I see. sorry for not reading the answers precisely ๐
Thank you for your answers! maybe we'll just upgrade jooq to avoid future problems like that ๐