-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java branch coverage gives wrong results with finally blocks. #13962
Comments
I believe the problem lies here: That is, the merging of
A A The initial construction of these objects is not important (and appears to be done correctly). A second merging step occurs to create a single Initially we might have trees that looks like this:
Note that there are two distinct branch expressions for the if statement on line 11. The expression for the second branch in line 8 must only consider the first two probes in the finally block, since the others represent conceptually distinct blocks that are not reached via that code path. However, during the merging step, all
And since the final probe is hit (because it represents the |
Branch coverage results may not be consistent when branches in a finally bock exist.
Consider the following:
There are three sets of branches - four for the first
if
(call it line 5), two for the secondif
(line 8), and 6 for theif
in the finally block (line 11). (The reason there are 6 for the finally block is because it is duplicated by the java compiler to account for the three possible paths into it).A coverage run when this is called with
foo(-1)
should cause two branches in the first if block to be taken (the second and third), none in the second if block, and one in the final if block. That is, we expect the following result:Instead, the following is observed:
This report suggests that a branch in the middle if block is being taken, and that three of the branches in the first are being taken, that we simultaneously satisfy
x == -1
andx != 1 && x != -1
(which is obviously incorrect).The line coverage part of the report (the
DA
lines) are reported correctly; this only affects the branch coverage part of the report.A simple reproduction is here: https://github.com/c-mita/bazel_issues/tree/master/java_try_finally_coverage/foo (added in c-mita/bazel_issues@8d10f8d)
The text was updated successfully, but these errors were encountered: