You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ignore switch case default cases which can't be covered #1211
JaCoCo version: (from right bottom corner of JaCoCo report)
0.8.6
Operating system:
Windows
Tool integration: Maven / Ant / CLI / API
Maven
Description of your use case:
Java Switch default cased can't be convered if all other cases are covered:
switch (enum) {
case CASE_1:
doSomething();
break;
case CASE_2:
doSomethingElse();
break;
default:
//Throw Exception in case a new Enum value is added in future and not yet supported
throw new UnsupportedOperationException("Not supported enum: " + enum.getName());
}
Jacoco should add an option to ignore/mark switch default cases as covered.
Current Behaviour
Switch default cases are makred as uncovered in case all other cases are covered even if coverage is not possible.
Wanted Behaviour
Jacoco should add an option to ignore/mark switch default cases as covered.
If possible Jacoco can check if all other cases are covered first, if not then a simple config option would be enough.
Possible Workarounds
Add unwanted Enums like UNKOWN or DEFAULT and try to cover default case with them.
Reacted by Mukul, Paul Matlashewski, Peacetrue, Artsiom Viahera, Pərvin Yaqubzadə, sibiarunachalam, Martin, Joao Leite, tibersept, tlsuresh and 22 more
Result is a falsely reported missed branch. I would classify it as a bug. JaCoco assumes an value outside the enum class has to be handled. But being outside the class definition, you cannot generate it.
Reacted by tlsuresh, wrayphi, Jakub Radlica, rained23, Himanshu Pandey, Mariano LEANCE, Forrest Hopkins, Ming Li and Sina Madani
It would be great if this could be filtered as it is impossible to cover via test and means that our coverage stats have false positives that we cannot address.
Also applies to the newer style switch for example:
`
enum Example {
ONE,
TWO
}
class ImpossibleToCover {
static String switchWithBranchThatCannotBeCovered(Example e) {
return switch(e) {
case ONE -> "one";
case TWO -> "two";
};
}
}
`
Reacted by Bruce Coveny, Jakub Radlica, Peter Großmann, Alex Ferreira, Dmitry Bufistov, Mohamed ElBeltagy and Mihai
@ ddatsh @M4urici0GM Please understand that all progress is documented here. Such only distract maintainers from the actual work. That's why we cleanup our issues from useless clutter.
Just chiming in to add that this issue extends to Java 14's switch expressions, making it impossible to have 100% code coverage if they are used, due to the implicit default value (which is unreachable).
Since the issue is still in under triage, I would like to point another impact. In case the project use coverage minimal limits, for presented Switch, with 4 branches including default, it is not possible to set coverage limit over than 75%, which is a low limit.
Reacted by Michael, RichardZh, Pavel Alexeev aka Pahan-Hubbitus and MCEmperor
Dear maintainers, could this issue be prioritized? It is open for a very long time and it is very annoying to use jacoco with the latest developments in the switch expression.
Is this not yet released or was it wrongly stated that it should fix this issue?
There are two different issues being described here. The one that was fixed was exhaustive switches incorrectly reporting an uncovered default case. The one you're talking about is exhaustiveness inference which Jacoco still does not do.
To manage expectation: JaCoCo analyzes the class files in scope one by one. JaCoCo has no "class loader" and does not analyze the structure of other classes (e.g. from libraries). This would be required to decide whether the switch on enum is exhaustive (for the specific version of that enum class).
As exhaustive switch expressions are properly handled by JaCoCo I tend to close this as "wont fix".
Activity
Copainbig commentedon Aug 7, 2021
I can look at that, but are we sure we want to do this, since here (PR-923), it was decided to not filter user code?
jorisgeer commentedon Dec 7, 2022
Result is a falsely reported missed branch. I would classify it as a bug. JaCoco assumes an value outside the enum class has to be handled. But being outside the class definition, you cannot generate it.
wrayphi commentedon Jan 5, 2023
It would be great if this could be filtered as it is impossible to cover via test and means that our coverage stats have false positives that we cannot address.
Also applies to the newer style switch for example:
`
enum Example {
ONE,
TWO
}
class ImpossibleToCover {
static String switchWithBranchThatCannotBeCovered(Example e) {
return switch(e) {
case ONE -> "one";
case TWO -> "two";
};
}
}
`
ddatsh commentedon May 15, 2023
any progress?
M4urici0GM commentedon May 15, 2023
any updates?
(idk why deleted my comment)
marchof commentedon May 15, 2023
@ ddatsh @M4urici0GM Please understand that all progress is documented here. Such only distract maintainers from the actual work. That's why we cleanup our issues from useless clutter.
daniel-frak commentedon Jun 23, 2023
Just chiming in to add that this issue extends to Java 14's switch expressions, making it impossible to have 100% code coverage if they are used, due to the implicit default value (which is unreachable).
forresthopkinsa commentedon Jul 26, 2023
Related to #771 and fixed in #1472
nioncode commentedon Apr 29, 2024
This is still broken for multi-line switch cases I think, see: #1472 (comment)Works fine in jacoco v0.8.12.
duracotton commentedon May 14, 2024
For me using Jacoco 0.8.12 it's still showing a missed branch:

byte-artisan commentedon Jun 26, 2024
Since the issue is still in under triage, I would like to point another impact. In case the project use coverage minimal limits, for presented Switch, with 4 branches including default, it is not possible to set coverage limit over than 75%, which is a low limit.
Hollerweger commentedon Apr 4, 2025
@forresthopkinsa Is this not yet released or was it wrongly stated that it should fix this issue?
shibicr93 commentedon Jan 29, 2026
Dear maintainers, could this issue be prioritized? It is open for a very long time and it is very annoying to use jacoco with the latest developments in the
switchexpression.shibicr93 commentedon Jan 29, 2026
I'm more than happy to lend a hand :-)
forresthopkinsa commentedon Jan 30, 2026
There are two different issues being described here. The one that was fixed was exhaustive switches incorrectly reporting an uncovered default case. The one you're talking about is exhaustiveness inference which Jacoco still does not do.
marchof commentedon Jan 31, 2026
To manage expectation: JaCoCo analyzes the class files in scope one by one. JaCoCo has no "class loader" and does not analyze the structure of other classes (e.g. from libraries). This would be required to decide whether the switch on enum is exhaustive (for the specific version of that enum class).
As exhaustive switch expressions are properly handled by JaCoCo I tend to close this as "wont fix".