Made by DeepSource

Methods annotated as non-nullable should not return null values JAVA-E1095

Bug risk

A method that is marked with annotations such as @Nonnull should not return explicit null values.

Returning null when the method is explicitly marked as non-null is a bad practice, since it defeats the purpose of the method being annotated in the first place.

Bad Practice

String someMethod() {
    // ...

    if (someCondition) {
        return null; // Not right!

    // ...
    return value;


Avoid returning null if the method is marked as not returning null.