Custom nullability annotations


I use the Minecraft plugin framework Sponge, and one of the design decisions is to use null only when completely necessary. Rather than annotate every single method, argument, and class in the framework, they have elected to make their own @NonnullByDefault annotation which gets applied to packages in Obviously, since it’s custom, Kotlin doesn’t recognize it as a nonnullability annotation and therefore leaves all platform types alone in interop.
Is there a way to create a compiler plugin to recognize Sponge’s @NonnullByDefault annotation and infer nonnullability on everything that isn’t explicitly annotated @Nullable? Compiler plugins in general seem completely undocumented.


They are… As far as I know the Kotlin team plans on releasing a public version of the compiler plugins at some point in the future, but they never said when. Right now plugins are an internal feature without a stable API.

As to your nullability problem, right now I would ignore it as best as you can. You can treat platform types as if they are non nullable so I don’t think this should really bother you too much.


I know I can ignore them, but there’s a lot of warnings that I end up suppressing.


Ok. I thought you could simply do something like this

val someValue: PlatformType = getPlatformType()  // now someValue is not nullable in this case

I think this should even create an error if getPlatformType is annotated with @Nullable.

Which warnings do you get exactly? I never really encountered any working with platform types (not that I know of anyways). Maybe there is something else you can do.