@NotNull on func arg warns arg == null is always false. But not really?

Viewed 15

Let's say I have a function with arguments annotated by Jetbrain's @NotNull, like so:

public static boolean birthdaysAreEqual(@NotNull clazz b1, @NotNull Birthday b2) {
     if (b1 == null || b2 == null) {
        // Custom handling here
        throw new NullPointerException("birthdays cannot be null");
    }
    return b1.isEqualTo(b2);
}

My IDE (IntelliJ) will warn me that the condition is always 'false'`, and suggest to remove the check, implying it is redundant.

But I'm able to call this function with null inputs, in which case the if conditional is useful for catching the problem early on and handling it.

Is it then not good behavior for the IDE to label the if condition as redundant? Or am I missing something (maybe another annotation that triggers actual input validation?)?

0 Answers
Related