Disable Intellij @Nullable on "implement methods" when base method is androidx @Nullable
Asked Answered
T

3

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?

Thremmatology answered 9/12, 2020 at 21:23 Comment(4)
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? ThanksMalvie
@OlgaKlisho AndroidX Annotations Version: 1.1.0. Preferences | Build, Execution, Deployment | Compiler exists, but there is nothing mentioned about annotations below that.Thremmatology
Your issue seems to be the duplicate of youtrack.jetbrains.com/issue/IDEA-247941 and it should be fixed since IntelliJ IDEA 2020.2 Please see the workaround description youtrack.jetbrains.com/issue/…Malvie
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.Thremmatology
P
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.

Pantoja answered 7/5, 2021 at 16:0 Comment(2)
Nice, this works. I think AS also fixed the default values at some point (currently using 2020.3.1-canary15)Thremmatology
Very annoying issue this fixed it, thanksHotchpotch
A
5

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

Acceptor answered 31/8, 2021 at 8:38 Comment(1)
Thanks for all the images, it made it alot easier to find them all.Hotchpotch
H
0

enter image description here

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

Hook answered 9/7, 2021 at 6:55 Comment(1)
It's discouraged to post images.Conway

© 2022 - 2024 — McMap. All rights reserved.