If a lookup switch contains two cases for the same code, as in
swtich (key) {
case 1:
case 2:
doSomething();
break;
default:
doSomethingElse();
}
The case 1 and case 2 will generate a lookup switch key/label pair (1, label) and (2, label). The instrumentation will only generate one "branch hit", and hence only one of the branches can ever be covered.
The situation is worse for table switches, where the compiler generates labels pointing to the default case for unspecified entries in the switch.
I've attached a patch, including a test case, that only generates one branch entry for every unique label (i.e., it makes sure the single "branch hit" instruction will correctly label the case as hit; the other case is no longer considered a potential branch.
This patch also contains the fix to FirstPassMethodInstrumenter.visitAnnotation since I found that issue only after fixing this one.