Search code examples
intellij-idea

Intellij refactoring, disable/customize generating "@org.jetbrains.annotations.NotNull"


Every time I extract method, this line is generated "for me":

@org.jetbrains.annotations.NotNull

around the method. 1. I don't have this on my class path, so it does not compile 2. even if I have, I don't want to include jetbrains annotations in my project. Even if I have more suitable (maybe) javax.validation.constraints.NotNull annotation on class path, intellij does not use that one.

questions:

  1. how to turn it off entirely?
  2. how to customize, which annotation to use?

Solution

  • The extract method dialog has a Generate annotations check box. When disabled it does not generate the nullability annotations. The state of this check box is remembered between invocations, so disabling it once is enough. extract method dialog

    If this check box does not appear, annotations for the extracted method should not be generated.

    It is possible to customize the annotation used in the settings of the Java | Probable bugs | Constant conditions & exceptions inspection. The configuration dialog looks this: enter image description here Use the check mark button, to mark the selected annotation as the one that should be used for code generation.