Skip to content
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

Branches Missed for switch on String #116

Closed
numeralnathan opened this issue Jul 9, 2013 · 1 comment
Closed

Branches Missed for switch on String #116

numeralnathan opened this issue Jul 9, 2013 · 1 comment
Labels
declined: duplicate ❌ This issue or pull request already exists

Comments

@numeralnathan
Copy link

The following code counts 1 branch missed per case statement.

String name;

...

switch (name)
{
case "1": return(1);
case "2": return(2);
...
default: return(-1);
}

I guess it is how switch on String is implemented. I assume javac compiles the switch by using hashcodes. If so, then each case has to test for string equality before executing the case. This would create a branch for each case and hence for code coverage the branch will be counted as missed.

There isn't anything the engineer should do to eliminate this missed branch. Jacoco should recognize that the branch is due to switch on String and simply ignore the branch in each case.

@marchof
Copy link
Member

marchof commented Jul 10, 2013

There is already an enhancement request to filter compiler artifacts #15.

"Switch on strings" is already on the filter candidate list: https://github.com/jacoco/jacoco/wiki/FilteringOptions

@marchof marchof closed this as completed Jul 10, 2013
@jacoco jacoco locked and limited conversation to collaborators Jan 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
declined: duplicate ❌ This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants