5

In Android Studio 4.2 beta 1, whenever I implement a method annotated with the androidx version of @Nullable, the IDE is automatically adding the jetbrains @Nullable annotation as well.

This is extremely annoying as it results in code like:

  @Nullable
  @org.jetbrains.annotations.Nullable
  @Override
  public String foo(@Nullable @org.jetbrains.annotations.Nullable String bar) {
    return null;
  }

Any way to prevent this?

Android
  • 1,230
  • 12
  • 20
  • Please tell what version of androidx annotations do you use? What default annotations do you have defined in Preferences | Build, Execution, Deployment | Compiler | Configure annotations? Thanks – Olga Klisho Dec 10 '20 at 15:34
  • @OlgaKlisho AndroidX Annotations Version: 1.1.0. Preferences | Build, Execution, Deployment | Compiler exists, but there is nothing mentioned about annotations below that. – Android Dec 11 '20 at 18:23
  • Your issue seems to be the duplicate of https://youtrack.jetbrains.com/issue/IDEA-247941 and it should be fixed since IntelliJ IDEA 2020.2 Please see the workaround description https://youtrack.jetbrains.com/issue/IDEA-247941#focus=Comments-27-4363983.0-0 – Olga Klisho Dec 14 '20 at 16:11
  • Thanks! oddly the `configure annotations` option is not in Android studio 4.2 beta 1. I believe the next release of Android Studio migrates to IDEA 2020, so it'll probably be there then. – Android Dec 16 '20 at 07:45

3 Answers3

14

I ran into this problem and was able to fix it by going to Settings > Editor > Inspections > Probable Bugs > Nullability > @NotNull / @Nullable annotations. Then under Options, click the Configure Annotations button, select androidx.annotation.Nullable and androidx.annotation.NonNull from the respective lists, and press the checkmark to select them as the annotations.

jnmorris
  • 151
  • 2
  • 7
4

As @jnmorris said, follow these steps :

Go to Settings > Editor > Inspections >

enter image description here

enter image description here

Find Java > Probable Bugs > Nullability Problems > @NotNull/@Nullable Problems

enter image description here

enter image description here

Click Configure Annotations button and check these items

enter image description here

ucMedia
  • 4,105
  • 4
  • 38
  • 46
0

enter image description here

Settings -> Editor -> Inspections -> Probable Bugs -> Nullability -> @NotNull/Nullable Problem -> Configure Annotations -> click androidx.annotation.Nullable and androidx.annotation.NonNull