Return of 'null'
Reports return
statements with null
return values. While occasionally useful, this construct may make the code more prone to failing with a NullPointerException
.
If a method is designed to return null
, it is suggested to mark it with the @Nullable
annotation - such methods will be ignored by this inspection.
Example:
class Person {
public String getName () {
return null;
}
}
After the quick-fix is applied:
class Person {
public @Nullable String getName () {
return null;
}
}
If the return type is java.util.Optional
, an additional quick-fix to convert null
to Optional.empty()
is suggested.
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
ReturnOfNull
Use the following options to configure the inspection:
Whether to ignore
private
methods. This will also ignore return ofnull
from anonymous classes and lambdas.Whether
null
values on array returns, collection object returns, plain object returns, or a combination of the three should be reported. Return ofnull
in methods with return typejava.util.Optional
are always reported.Click Configure annotations to specify which annotations should be considered 'nullable'.
Here you can find the description of settings available for the Return of 'null' inspection, and the reference of their default values.
Inspection Details | |
---|---|
By default bundled with: | |
Can be installed with plugin: | Java, 243.23126 |
Thanks for your feedback!