hi, is there a compiler setting to mark all object...
# announcements
t
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
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
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
Are you sure this method is annotated? What is nullable annotation is used?
j
what version of jooq are you using? he added nullable/notnull annotations in 3.14.x
t
ah so if there is NO annotation the type is noch recognized nullable?
g
No, if there is no annotation, it will be platform type, as Nicolas wrote above
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
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 🙂