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

1.2k views Asked by At

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?

3

There are 3 answers

2
jnmorris On BEST ANSWER

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.

1
ucMedia On

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

1
Nhật Bảo On

enter image description here

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