Java

Java

By DeepSource

Use of @Nonnull, @CheckForNull, or @Nullable detected on primitive declaration JAVA-W1063

Anti-pattern

Primitive types can't be null. Marking primitive parameters, return values, or fields with CheckForNull, Nullable, or NonNull is useless and only adds confusion. These annotations should be removed to improve readability of code.

Bad Practice

class Example {
    @Nullable private int field = 10;

    @CheckForNull
    public int method(@NonNull int param) {
        // ...some code
    }
}

Recommended

Remove these annotations from primitive declarations.

class Example {
    private int field = 10;

    public int method(int param) {
        // ...some code
    }
}
}

References