Anoop M Nair
Anoop M Nair

Reputation: 1087

Try with multiple resource causes a sonar qube issue

Please see the code snippet

try (InputStream inputStream = this.getClass().getClassLoader()
                .getResourceAsStream("hello.txt");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) {

But sonarQube complaints below error in the above line   

Correctness - Nullcheck of value previously dereferenced(line starting with BufferedReader ) .

Please help to resolve this issue  

Upvotes: 1

Views: 690

Answers (1)

Arnaud Claudel
Arnaud Claudel

Reputation: 3138

It's because getClassLoader().getResourceAsStream("hello.txt") can return null and you're using it just after to create the BufferedReader, without checking for null value.

Upvotes: 2

Related Questions