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

Partial branch coverage being shown on exhaustive switch expressions #1531

Closed
rishabharoraa opened this issue Nov 1, 2023 · 1 comment
Closed
Assignees
Projects

Comments

@rishabharoraa
Copy link

rishabharoraa commented Nov 1, 2023

Steps to reproduce

  • JaCoCo version: 0.8.11
  • Operating system: MacOS Ventura Version 13.5
  • Tool integration: CLI
  • Steps:

File I used SwitchExpressionTarget.java

public class SwitchExpressionTarget {

	private enum E {
	        ZERO, ONE;
	}

	private static int target(E e) {
                int a = -1;
		switch (e) {
			case ZERO -> a = 0;
			case ONE -> a = 1;
		};
                return a;
	}

	public static void main(String[] args) {
		target(E.ZERO);
		target(E.ONE);
	}

}

By doing:

$ java -version
openjdk version "17.0.7" 2023-04-18 LTS
OpenJDK Runtime Environment (build 17.0.7+7-LTS)
OpenJDK 64-Bit Server VM (build 17.0.7+7-LTS, mixed mode, sharing)

$ javac SwitchExpressionTarget.java

$ java -javaagent:jacoco-0.8.11/lib/jacocoagent.jar SwitchExpressionTarget 

$ java -jar jacoco-0.8.11/lib/jacococli.jar \                              
    report jacoco.exec \
    --classfiles SwitchExpressionTarget.class \
    --sourcefiles . \
    --html report

Expected behaviour

The report must show full coverage

Actual behaviour

The report shows 1 missed branch

image

@rishabharoraa rishabharoraa added the type: bug 🐛 Something isn't working label Nov 1, 2023
@Godin Godin added this to Awaiting triage in Filtering via automation Nov 1, 2023
@Godin Godin self-assigned this Nov 1, 2023
@Godin
Copy link
Member

Godin commented Nov 1, 2023

This

	private static int target(E e) {
                int a = -1;
		switch (e) {
			case ZERO -> a = 0;
			case ONE -> a = 1;
		};
                return a;
	}

is switch statement and not switch expression.

Exhaustive switch expression is

        private static int target(E e) {
                int a = switch (e) {
                        case ZERO -> 0;
                        case ONE -> 1;
                };
                return a;
        }
Screenshot 2023-11-01 at 17 45 48

@Godin Godin closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2023
Filtering automation moved this from Awaiting triage to Done Nov 1, 2023
@Godin Godin added declined: invalid ❌ and removed type: bug 🐛 Something isn't working labels Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Filtering
  
Done
Development

No branches or pull requests

2 participants