Set usage of Objects.isNull and Objects.nonNull as code smells

While using this method does not create any problem, I consider it a code smell because this method was designed to be used along with lambdas and not for other usages

Description of the method from the java docs :

API Note:

This method exists to be used as a Predicate , filter(Objects::isNull)

  • snippet of Noncompliant Code
if (Objects.isNull(object)) {
  • snippet of Compliant Code (fixing the above noncompliant code)
if (object == null) {

  • exceptions to the Noncompliant Code, i.e. conditions in which the noncompliant code should not raise an issue so that we reduce the number of False Positives.

This should not be marked as a code smell when used within java streams.Example :

Java docs : Objects (Java Platform SE 8 )

Hello @sonaruser1231, thanks for the suggestion.

I think it makes sense, I created a draft description of the rule, I let you have a look if you are interested.

I can not say when we will implement it, you can follow the progress on the related ticket: SONARJAVA-4274.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.