KAnnotator 0.1 is out

Andrey Breslav

We announced KAnnotator back in December: it helps you against NPEs in Java and makes your Kotlin code nicer. Today we are pleased to announce a KAnnotator Plugin for IntelliJ, version 0.1. It is available from the plugin repository.

Why Infer Annotations

An excerpt from an earlier blog post, explaining what KAnnotator is:

Since Kotlin M3, you can use external annotations to tell the system that your methods return/take non-null values. This mechanism is useful even if you don’t use Kotlin: you can turn on nullability inspections for Java too (and I totally recommend you to do so).

One problem about this used to be that, while you can annotate your own code while you write it (and we do it all the time at JetBrains), your favorite library is not annotated, and it is so big, you can’t annotate it manually.

The key thing here is that ‘manually’. A programmer is a lazy creature, and by virtue of our laziness, we want to automate as much as we can. KAnnotator is a tool that annotates your libraries automatically (the tool is written in Kotlin, of course).

How it works, in a nutshell: you have your library as a jar (or a number of jars), you tell KAnnotator to infer annotations for these jars, and get a bunch of .xml files back. They contain annotations for methods and fields, for example:

Now, you can attach these annotations to your project, and both Java IDE and Kotlin compiler will see them.

We used KAnnotator to infer annotations for JDK that ship with Kotlin. Now you can use it as well: to annotate your own libraries.


KAnnotator ships as a separate plugin for IntelliJ IDEA 12 or higher (both 12.0.4 and 12.1 will work). Note that the Kotlin plugin is not required. To install the plugin, follow the instructions from here.


No you can call Analyze -> Annotate Jar Files… (from either Main menu or context menu)

You get a dialog like this:

There you specify what JAR files you want analyzed and where to put the results, i.e. XML files containing annotations. By default, KAnnotator will attach the annotation to the libraries you call it on.


So, when you see Kotlin complaining about nullable types coming from Java, all you need to do is run KAnnotator once on that Java library, and it will turn your red code green.

If it does not, maybe KAnnotator is not smart enough, but maybe that method actually returns null?

Comments below can no longer be edited.

13 Responses to KAnnotator 0.1 is out

  1. Maarten says:

    March 30, 2013

    Interesting tool. I’d like to try it on a large maven-based project I have at work, but I’d need an hour just to click all the checkboxes on all the libraries.
    Could you include a ‘select all’ button in the next version?

    • Andrey Breslav says:

      March 30, 2013

      Sure. Meanwhile you can select all (Ctrl+A / Cmd+A) and press Space to check the boxes.

      • Maarten says:

        April 2, 2013

        Thanks for the tip, that works quite well.

        While trying to run all several hundred jar through KAnnotator, eventually IDEA would run out of memory. Is this a known issue?

        • Andrey Breslav says:

          April 2, 2013

          Yes, we are working on optimizing memory consumption.

      • Jon Nichols says:

        April 7, 2013

        KAnnotator puts the annotations in a directory for each library. However, this doesn’t work well with Maven, where I’d just like to set a root and have all of the annotations under the same root. How do I make KAnnotator not include the library directory and just populate a common tree?

        • Andrey Breslav says:

          April 7, 2013

          This is not supported now. Feel free to file an issue in the bug tracker or a pull request on github

  2. Ian Clarke says:

    March 31, 2013

    I’ve had some issues with IDEA assigning various nullability annotations to things, that then cause them to break when my colleagues try to use the source code in a different IDE (eg. Eclipse), because the annotations aren’t in the classpath (we use Maven, and try to keep everything cross-IDE).

    Would you mind clarifying how to take advantage of these nullability annotations in a cross-IDE manner (at least so that it doesn’t break the source code in other IDEs)?

    • Andrey Breslav says:

      April 1, 2013

      In what way does it break the code? (IntelliJ only issues warnings upon nullability issues, never errors, so the code should always compile).

      • Ian Clarke says:

        April 1, 2013

        In that it added annotations to the code that weren’t in any Maven dependency (IIRC it was some auto-generated method, sorry – it was a while ago). Worked locally, but not elsewhere.

        I guess the broader question is: If IDEA nullability annotations are IDEA-specific, how does this work when other people working on the source code might be using different IDEs.

        • Andrey Breslav says:

          April 1, 2013

          As far as I know, tools like FindBugs support custom annotations, and we are going to have JSRs 305 and 308 out soon, finally standardizing these annotations.

  3. Maarten says:

    April 2, 2013

    I’ve found a jar file that causes a JetNullPointerException when KAnnotator processes it: http://mavenhub.com/mvn/thirdparty-releases/gnu-getopt/getopt/1.0.12-brew

    The exception has been sent as error report 480295 to the exception analyzer.

  4. Gri says:

    March 28, 2014


    Problems with aS =”123.34″.split(“.”) ( js project)
    aS.size == 7 ???

    fun main(args : Array) {
    println(“Hello, world!”)
    val aS = “123.34”.split(“.”)
    println( aS.size)

    Hello, world!

    Generated JavaScript code
    (function () {
    ‘use strict’;
    var _ = Kotlin.defineRootPackage(null, /** @lends _ */ {
    main: function (args) {
    Kotlin.println(‘Hello, world!’);
    var aS = Kotlin.splitString(‘123.34’, ‘.’);
    Kotlin.defineModule(‘JS_TESTS’, _);