Search code examples
javaspring-data-jpasonarqube

Sonar Qube says Objects.inNull always evaluates to false resulting code build fail in production


For some reason sonar reports(Client reports) that the below Objects.isNull always evaluates false disabling the production upgrade. can someone help me understand why does that happen from the client sonarqube and how to fix?

Iterable<Sim> result = repository.findAllById(list);
        
        if (Objects.isNull(result)) {  // Sonar thinks it always evaluates to false 

Solution

  • result may be empty but it will not be null and Objects.isNull() will therefore never return true.

    If no mathing data is found in the database, hasNext() returns false for every Iterator returned by iterator().

    While you are technically able to create your own implementation, it would likely not make sense to return null.

    If you really want to do it and have a reason to, you can add a //NOSONAR comment explaining it in the same line and the warning will disappear.