JDK library nullability meta-data

I have an idea I’d like to try to implement, but first I’d like to hear some feedback. It’s about adding nullability meta-data to JDK classes and possibly other libraries so we get rid of some platform types. It consists of three steps

  1. Get the meta-data. First, we have to figure out which parameters and return types in JDK libraries are (non)nullable. There are tools for that, I suppose they do not work perfectly, but I guess we can get some semiautomatic process going. In the worst case, we can crowd-source it.
  2. Store the meta-data. In the ideal world we would just add @Nullable annotations to the OpenJDK, but I’m afraid it’s not feasible for multiple reasons. But we can store the meta-data in an external format (something like typescript type information)
  3. Integrate the external format to Kotlin toolchain.

I think that all the steps are far from trivial but feasible. What do you think?


I like the idea, but this needs some way of ensuring the meta-data is up to date. If the meta data isn’t provided by the author of a library there is no way of ensuring that the Nullability of a function doesn’t change from one version to another. The more manual step 1 is the more effort needs to be spend here. I don’t think this is an immpossible task, but unless this is properly handled it will make this idea practically useless (except for the java stdlib, which is unliekly to change).