Reputation: 5655
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.
Upvotes: 3
Views: 3580
Reputation: 10833
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.
Upvotes: 5