Hi,
Versions: SonarJava 5.9.1, SonarQube 6.7.3
The method ‘createFoo’ in the example below can return a null value. Sonar rule squid:S2583 assumes it to be non-null. It seems this is caused by the type of java.lang.Closeable
package com.example;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.io.Closeable;
import java.io.IOException;
public class NullableClosable {
private final Factory factory;
public NullableClosable(Factory factory) {
this.factory = factory;
}
boolean m() throws IOException {
Closeable foo = factory.createFoo();
if (foo == null) { // <-- squid:S2583 Change this condition so that it does not always evaluate to "false"
return false;
}
foo.close();
return true;
}
public interface Factory {
@Nullable Closeable createFoo();
}
}
Cheers,
Andreas