Skip to content
Advertisement

How to stop IntelliJ from automatically importing org.jetbrains.annotations in Java?

My superclass has a method signature with parameters that use javax annotations like so:

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public abstract class Nanana {

    // ...

    protected abstract void nanaFunction(
        @Nonnull final Parameter parParameter1,
        @Nullable final Parameter parParameter2
    ) { /* ... */ }
}

And when I inherit from this class in a different file without manually importing the annotations, it autocompletes my override like so (notice the annotation imports):

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ConcreteNanana extends Nanana {

    // ...

    @Override
    public void nanaFunction(
        @NotNull final Parameter parParameter1,
        @Nullable final Parameter parParameter2
    ) { /* ... */ }
}

How do I configure IntelliJ to import the same annotations as the superclass? I am using IntelliJ 2020.3.3 Ultimate.

Advertisement

Answer

As mentioned here

This is a defect and you can solve it by:

Settings --> Inspections --> Java --> Probable bugs --> Nullability problems --> @NotNull/@Nullable problems --> Configure Annotations

And Set the defaults

javax.annotation.Nullable
javax.annotation.Nonnull

Restart and should be ok.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement