简体   繁体   中英

SonarQube - Why condition Coverage metrics on catch statement

I have the java code like

try (FileInputStream fileInputStream = new FileInputStream(filePath);
            PrintWriter out = response.getWriter()) {
        while ((i = fileInputStream.read()) != -1) {
            out.write(i);
        }
    } catch (IOException e) {
        throw new IOException(e);
    }

For this I have all the test written and I am using Sonarqube as code coverage tool. But unfortunately conditional coverage result( 2 conditions are covered by test ) is coming in my catch statement. As far my knowledge, conditional coverage is apply only for condition check. Why it is showing in catch statement. Can someone shed some light here.

This an issue on JaCoCo side due to the try-with-resource construction : The bytecode generated have several branches in order to safely close the open resource and JaCoCo instrument bytecode and report some of those branches as uncovered.

See this issue : https://github.com/jacoco/jacoco/issues/82 and this one https://github.com/jacoco/jacoco/issues/15 for more detailed explanation.

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