This happens with sb-contrib version 7.6.4 (current release) and OpenJDK 17 (Eclipse Temurin).
Example code:
public final class Example
{
public static String example(String resource)
{
try (InputStream input = Example.class.getResourceAsStream(resource))
{
if (input == null)
{
return null;
}
else
{
return new String(input.readAllBytes(), StandardCharsets.ISO_8859_1);
}
} // bugs reported on this line
catch (IOException ex)
{
throw new UncheckedIOException(ex);
}
}
}
NP_LOAD_OF_KNOWN_NULL_VALUE and RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE are incorrectly reported, due to the null test. These false positives are probably caused by the try-with-resources byte code. Null resource values are valid in try-with-resources statements. Due to the scope of the resource variable, it would be inconvenient to move the null check outside the try-with-resources statement.
Applying @SuppressFBWarnings to just the resource variable declaration also doesn't work.
This happens with sb-contrib version 7.6.4 (current release) and OpenJDK 17 (Eclipse Temurin).
Example code:
NP_LOAD_OF_KNOWN_NULL_VALUE and RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE are incorrectly reported, due to the null test. These false positives are probably caused by the try-with-resources byte code. Null resource values are valid in try-with-resources statements. Due to the scope of the resource variable, it would be inconvenient to move the null check outside the try-with-resources statement.
Applying
@SuppressFBWarnings
to just the resource variable declaration also doesn't work.