https://kotlinlang.org logo
#getting-started
Title
# getting-started
b

Bernhard

02/29/2024, 1:36 PM
I'm consuming a library that has properties annotated with @NotNull (jakarta) but not @Nullable; it also provides no package-info.java; is there a way to tell Kotlin that types without @NotNull in a package root should be treated as nullable?
1
v

Vampire

02/29/2024, 1:42 PM
Did you try to annotate the package in
package-info.java
with
@Nullable
?
b

Bernhard

02/29/2024, 1:43 PM
it's a jar from maven, can I override that locally when pulling that down as a dependency?
v

Vampire

02/29/2024, 2:01 PM
Don't think so
j

Johan

02/29/2024, 6:34 PM
If you are the owner of that Java lib I think you can add annotations for "NotNull" https://reflectoring.io/spring-boot-null-safety-annotations/ Ubleash uses their own in https://github.com/Unleash/unleash-client-java/blob/main/src/main/java/io/getunleash/package-info.java#L1
b

Bernhard

02/29/2024, 6:35 PM
unfortunately I'm not
j

Johan

02/29/2024, 6:37 PM
I think I read it all wrong. I would have guessed that the values/values returned by Java code to be nullable if not defined otherwise?
b

Bernhard

02/29/2024, 6:38 PM
at least how I kinda understood it by now: you need to annotate the package for that to work
I think there are annotations on how nullability is decided if an annotation is absent
v

Vampire

02/29/2024, 7:17 PM
I would have guessed that the values/values returned by Java code to be nullable if not defined otherwise?
Without annotation they are potentially nullable, they are so-called platform types, the ones with
!
suffix in the IDE type display.