Skip to content

Instantly share code, notes, and snippets.

@TheNullicorn
Created January 22, 2026 03:43
Show Gist options
  • Select an option

  • Save TheNullicorn/90a619796c40f20ae1fcf13094c1a57d to your computer and use it in GitHub Desktop.

Select an option

Save TheNullicorn/90a619796c40f20ae1fcf13094c1a57d to your computer and use it in GitHub Desktop.

When IntelliJ autofills an override for a method, the nullability annotations it chooses may not be from the library you want:

image image

Luckily this can be changed! Though the settings for it are buried a bit.

image
  1. On the lefthand side, navigate to the menu Editor > Inspections
  2. In the inspections tree, find and select the entry @NotNull/@Nullable problems. It should be under:
    • Java
      • Probable bugs
        • Nullability problems
          • @NotNull/@Nullable problems
  3. On the righthand side, under Options, scroll down and click the button Configure Annotations.... A popup window should open.
image
  1. In the new window, find and select the entry you want to take priority. In the screenshot, that is javax.annotation.Nullable
  2. Click the Up button at the top of the list until your entry is the first one
  3. At the top of the window, switch to the NotNull tab and repeat steps 1 and 2

After that, click the OK button on both windows to save your settings. Now whenever IntelliJ autofills an overridden method, it should insert the annotations that you chose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment