https://kotlinlang.org logo
Title
p

Pablichjenkov

03/22/2023, 4:19 PM
Is there a compiler flag to enforce kotlin interaction with java, is always declared nullable.
m

MerlinTHS

03/22/2023, 6:02 PM
You mean the platform types?
p

Pablichjenkov

03/22/2023, 6:05 PM
Yeup
m

MerlinTHS

03/22/2023, 6:23 PM
The only option I remember is -Xnullability-annotations=@<package-name>:<report-level> but it only addresses the handling of explicitly annotated properties. So as far as I know there is no general flag for that. Would be an idea for a compiler plugin or an IDE analysis extension ( Since there is a new fronted-independent Analysis API )
p

Pablichjenkov

03/22/2023, 6:32 PM
Thanks for the answer, I believe it would be a good tool, lot of java code out there and many developers normally forget the nullable annotations
m

MerlinTHS

03/22/2023, 7:06 PM
I'm currently working on a Compiler Plugin for dealing with optional as if they were normal types. Maybe something like a stricter null safety policy would fit into the project. ( You then could toggle it either via a command line option or the plugins gradle extension )
p

Pablichjenkov

03/22/2023, 7:23 PM
Sounds great, basically my need is for a tool that highlights the places in code where a platform type is referenced from the kotlin side and it is not declared nullable. And no nullability annotations have been used in the java side The problem is we have a big java codebase, source code and libraries, and we get a lot of npe in kotlin just for the relaxed compiler that doesn't enforce all java interoperability as nullable.
a

Adam S

03/22/2023, 10:09 PM
if you’re interested in a hypothetical workaround, I have an idea: add a
@Nullable
as a package annotation in the Java code. And then, as required, mark non-null functions/properties/etc as
@NonNull
.
p

Pablichjenkov

03/22/2023, 10:46 PM
I will give it a try, I also see a plugin related to nullability in the plugin marketplace, will check that out too
Tried the package-info.java thing but no luck. Set the package to be Nullable but the compiler seems to ignore it.
I found a lint rule that solves my problem