Java

Java

Made by DeepSource

Nullable parameters should be checked for null before use JAVA-E1067

Bug risk
Critical

This parameter is always used as if it is non-null, but the parameter may be null when the usage occurs.

Bad Practice

public void doWork(MyClass myClass) {
    // ...

    // Dereference without a null check.
    myClass.myField = "value";

    // ...
}

// ...

MyClass nullable;

// ...

if (condition) nullable = new MyClass();
else nullable = null;

// ...

doWork(nullable); // If nullable is null, we will get an NPE

Recommended

If you require that the parameter should never be null, consider changing the annotation to @NonNull or an equivalent annotation to indicate that the method expects the value to be non-null.

If the variable is likely to be null, consider performing a null check before using the variable.

References