Skip to content

JaCoCo 0.8.14 version reduces the test coverage results for switch statement (parameter type String) when used with forEach #2011

@Sofiya-Sundaramoorthy

Description

@Sofiya-Sundaramoorthy

JaCoCo version: 0.8.14
JDK version: 25
OS: Mac
Tools: Maven
Github: https://github.com/Sofiya-Sundaramoorthy/jacoco-0.8.14-switch-statement
Brief description: When upgrading the JaCoCo version from 0.8.12 to 0.8.14 to support JDK25 upgrades, I noticed that the test coverage dropped for a switch statement in combination with forEach.

checkData method takes List as parameter which then loops using forEach to pass data to a switch statement

// method

protected String checkData(List<String> datas) {
        datas.forEach(data -> {
            switch(data) {
                case "a" -> System.out.println("first data");
                case "b" -> System.out.println("second data");
                case "c" -> System.out.println("third data");
                default -> System.out.println("default data");
            };
        });
        return null;
    };

//testcase

@Test
	void testData() {
		var application = new SwitchStatementApplication();
		var result1 = application.checkData(List.of("a", "b", "c", "d"));
		assertNull(result1);
	}

The minimal reproducible code is in the github repo https://github.com/Sofiya-Sundaramoorthy/jacoco-0.8.14-switch-statement

Note: The switch statement takes parameter of type String which gives 78% test coverage. However, when passing parameter type of Int the coverage is 100%

Expected behaviour: The combination of forEach + switch (parameter type as String) should produce 100% test coverage

Actual behaviour: The combination of forEach + switch (parameter type as String) produces 78% test coverage

Please refer the screenshots

JaCoCo 0.8.12 with JDK21

Image Image

JaCoCo 0.8.14 with JDK25

Image Image

Metadata

Metadata

Assignees

Type

No type

Projects

Status

In Progress

Relationships

None yet

Development

No branches or pull requests

Issue actions