javaintellij-ideaintellij-plugin

"String @NotNull []" syntax causes "'@NotNull' not applicable to type use" in intellij IDEA plugin


I am trying to fix a few bugs in an old, now open-sourced intellij IDEA plugin (the CFML Plugin)

The following Syntax appears several times in multiple files and generates an error:

String @NotNull []

This is what the error looks like:

enter image description here

The example is from the following file: https://github.com/JetBrains/intellij-plugins/blob/master/CFML/src/com/intellij/coldFusion/model/CfmlUtil.java#L249

What does this syntax do? I haven't found any information on it. It seems like @NotNull String[] would do exactly the same thing without the error.

How do I get this to work? I have followed the setup instructions for setting up a development environment and creating a plugin project exactly. What is my environment missing to run this code?


Solution

  • I suspect that you don't have the JetBrains Annotations library installed. Please follow the installation guide here.

    The String @NotNull [] syntax consists of the @NotNull annotation applied to the String[] type. Note that this is different from @NotNull String[], in which @NotNull only applies to the String type. The annotation is used in this way to say that the string array returned will not be null, but the strings inside it might be.

    Compare: