How to use kotlin-jdk-annotations?

I’d love to have the Kotlin compiler perform nullability checks for Kotlin code interacting directly with the Java standard library, both in IntelliJ and in Gradle builds. I suppose this is what org.jetbrains.kotlin:kotlin-jdk-annotations:1.0.0-beta-4584 is for, but I can’t find any information on how to make use of it. Merely adding it to my project’s compile class path doesn’t seem to make a difference. Can somebody explain (and document) how kotlin-jdk-annotations is supposed to be used?

It’s not supposed to be used. We no longer support external annotations in the compiler and no longer ship annotations for the JDK.

Does this mean we’ll never get proper nullability checking for (core parts of) the Java standard library? Given that much of stdlib is an extension rather than replacement of the Java standard library, and any non-trivial JVM app written in Kotlin will make heavy use of the Java standard library, this would be very sad news.

I hope this feature has been mainly dropped for 1.0, not dismissed in general.

PS: Contrary to your statement, the latest Kotlin version published on Maven Central still comes with kotlin-jdk-annotations.

kotlin-jdk-annotations on Maven is an empty jar. I guess we’re still shipping it for compatibility reasons, and will stop doing so in 1.0.

I’m not aware of any plans to restore support for external annotations that was removed recently.

That’s disappointing to hear. Do you have a link that explains the rationale behind this move? I can’t find anything.

The main argument is stability of compilation. We don’t want the behavior of the compiler to depend on whether an optional file has been given to it as an argument.

Correctness is also an important point. As soon as you start making statements about the behavior of other people’s code, you run into a risk of getting things wrong - and we did have incorrect annotations in kotlin-jdk-annotations. And it’s hardly possible to automatically verify the correctness of external annotations for a given library.

Thanks for the explanation. These are valid points, but it’s a big loss for the Java standard library in particular. Perhaps mandatory, community-verified annotations for core parts of the Java standard library could be a sweet spot?