简体   繁体   中英

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

这是因为getClassLoader().getResourceAsStream("hello.txt")可以返回null并且您在创建BufferedReader之后就使用了它,而无需检查null值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM