GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add filter for exhaustive switch expression by Godin · Pull Request #1472 · jacoco/jacoco

Conversation

@Godin

@Godin Godin commented Jun 5, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Before this change for the following Example.java

enum Example {
    A, B;

    static int example(Example e) {
        return switch (e) {
        case A -> 1;
        case B -> 2;
        };
    }

    public static void main(String[] args) {
        example(A);
        example(B);
    }
}

using

openjdk version "17.0.2" 2022-01-18 LTS
OpenJDK Runtime Environment Zulu17.32+13-CA (build 17.0.2+8-LTS)
OpenJDK 64-Bit Server VM Zulu17.32+13-CA (build 17.0.2+8-LTS, mixed mode, sharing)

execution of

javac Example.java -d classes
java -javaagent:jacocoagent.jar -cp classes Example
java -jar jacococli.jar report jacoco.exec --classfiles classes --sourcefiles . --html report

produces

before before

and after this change

after after

Fixes #771

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ice1000, roman-svystun, and lolo101 reacted with thumbs up emoji ice1000, KirillSmirnow, roman-svystun, and lolo101 reacted with hooray emoji ice1000, bcersows, and roman-svystun reacted with heart emoji ice1000, KirillSmirnow, and roman-svystun reacted with rocket emoji
All reactions
  • 👍 3 reactions
  • 🎉 4 reactions
  • ❤️ 3 reactions
  • 🚀 3 reactions
@Godin
(WIP) update validation test
89b8b94
@Godin Godin self-assigned this Jun 5, 2023
@Godin Godin added type: enhancement component: core.filters labels Jun 5, 2023
@Godin Godin added this to the 0.8.11 milestone Jun 5, 2023
@Godin
Godin force-pushed the ExhaustiveSwitchFilter branch from 643dcfa to ae0663f Compare June 5, 2023 09:17
@marchof marchof mentioned this pull request Jun 5, 2023
Add filter for exhaustive switch-expression #771
Closed
@Godin
(WIP) add unit tests
749871b
@Godin
Godin force-pushed the ExhaustiveSwitchFilter branch from ae0663f to 749871b Compare June 5, 2023 09:55
@Godin Godin changed the title Add filter for exhaustive switch-expression Add filter for exhaustive switch expression Jun 5, 2023
Godin added 2 commits June 5, 2023 12:03
@Godin
(WIP) add filter
d62121d
@Godin
(WIP) add unit test
f26e464
@Godin
Godin force-pushed the ExhaustiveSwitchFilter branch from 6a99e78 to f26e464 Compare June 5, 2023 10:51
@Godin
(WIP) update filter
1b11327
@Godin Godin added the language: Java Tickets about Java language support label Jun 5, 2023
Godin and others added 2 commits June 6, 2023 09:55
@Godin
Merge branch 'master' into ExhaustiveSwitchFilter
f518bc3
@Godin
(WIP) update changelog
167c0d5
@Godin
Godin marked this pull request as ready for review June 6, 2023 11:31
@Godin
Godin requested a review from marchof June 6, 2023 11:31
marchof
marchof reviewed Jun 8, 2023
View reviewed changes
Comment thread org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/ExhaustiveSwitchFilter.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

marchof
marchof reviewed Jun 8, 2023
View reviewed changes
Comment thread org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/ExhaustiveSwitchFilter.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

marchof
marchof reviewed Jun 8, 2023
View reviewed changes
Comment thread org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/ExhaustiveSwitchFilter.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

marchof
marchof approved these changes Jun 8, 2023
View reviewed changes

@marchof marchof left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work again! I left some formal comments you might want to consider.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Godin and others added 3 commits June 14, 2023 16:14
@Godin
Apply suggestions from code review
f813939
@Godin
Merge branch 'master' into ExhaustiveSwitchFilter
9702021
@Godin
Adjust expected size of distribution
b94bc36
marchof
marchof approved these changes Jun 14, 2023
View reviewed changes
@marchof
marchof merged commit 8271afb into jacoco:master Jun 14, 2023
@Godin
Godin deleted the ExhaustiveSwitchFilter branch June 14, 2023 21:25
@DamnClin DamnClin mentioned this pull request Jul 8, 2023
Rename @Generated to @ExcludeFromGeneratedCodeCoverage seed4j/seed4j#6804
Merged
@forresthopkinsa forresthopkinsa mentioned this pull request Jul 26, 2023
Ignore switch case default cases which can't be covered #1211
Open
@eortega-pjr eortega-pjr mentioned this pull request Jan 25, 2024
exhaustive switch expression is not fully covered #1571
Closed
@nioncode

nioncode commented Apr 29, 2024

Copy link
Copy Markdown

@Godin should this already handle multi-line switch expressions? I still get missed branch warnings in my code, where I have something like:

enum Example {
    A, B;

    static int example(Example e) {
        return switch (e) {
        case A -> {
            if (false) {
              throw new InvalidStateException();
            }
            yield 1
        };
        case B -> {
            if (false) {
              throw new InvalidStateException();
            }
            yield 2;
        };
    }

    public static void main(String[] args) {
        example(A);
        example(B);
    }
}
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Godin

Godin commented Apr 29, 2024

Copy link
Copy Markdown
Member Author

@nioncode for the following Example.java which is the same example as yours after fixing compilation errors

enum Example {
    A, B;

    static int example(Example e) {
        return switch (e) {
        case A -> {
            if (false) {
              throw new IllegalStateException();
            }
            yield 1;
        }
        case B -> {
            if (false) {
              throw new IllegalStateException();
            }
            yield 2;
        }
        };
    }

    public static void main(String[] args) {
        example(A);
        example(B);
    }
}

using

openjdk version "21" 2023-09-19
OpenJDK Runtime Environment (build 21+35-2513)
OpenJDK 64-Bit Server VM (build 21+35-2513, mixed mode, sharing)

execution of

javac Example.java -d classes
java -javaagent:jacoco-0.8.12/lib/jacocoagent.jar -cp classes Example
java -jar jacoco-0.8.12/lib/jacococli.jar report jacoco.exec --classfiles classes --sourcefiles . --html report

produces the following report

Screenshot 2024-04-29 at 11 38 05 Screenshot 2024-04-29 at 11 37 46
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nioncode

nioncode commented Apr 29, 2024

Copy link
Copy Markdown

This is true. Sorry, I ran this through gradle and it seems it does not pick up the latest version by default.

Just for others, if you use the jacoco plugin in gradle, you can force a specific version via:

plugins {
  id "jacoco" // note: don't specify a version here, specify it in the jacoco block below
}

jacoco {
  toolVersion = "0.8.12"
}

Everything works fine as is, sorry for the noise.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Joannanas Joannanas mentioned this pull request Jun 6, 2024
Missing branch coverage while using Sealed Classes #1219
Closed
@Godin Godin mentioned this pull request Jan 14, 2025
Provide context information when zip reading throws IllegalArgumentException #1833
Merged
odd-contributor Bot pushed a commit to opendatadiscovery/odd-platform that referenced this pull request Sep 11, 2026
@RamanDamayeu @claude
build(api): pin JaCoCo 0.8.12 so an exhaustive switch expression's sy…
e8b126d
…nthetic default is no longer counted

javac emits a default arm for an exhaustive enum `switch` expression that throws if the enum ever gains a
constant — 4 instructions and 1 branch no test can reach. JaCoCo 0.8.9 (Gradle 8.5's default) counts them;
0.8.11+ filters them (jacoco/jacoco#1472). On a 157-instruction class that arm alone is 2.55%, so a small new
class with every reachable line covered still reads below the 98% changed-files floor. odd-platform-api has 18
such `return switch (…)` sites in measured code; their numbers move up, nothing else changes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01D6rCJ3zvUAsBZ5H9XYpfmG
@odd-contributor odd-contributor Bot mentioned this pull request Sep 11, 2026
Search: a term or a query example can say why it matched — the (?) badge on every kind, and a highlight that is text, never HTML (ST-12 of #1825) opendatadiscovery/odd-platform#1894
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@marchof marchof marchof approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@Godin Godin

Labels

component: core.filters language: Java Tickets about Java language support type: enhancement

Projects

Current work items
Status: Done
Filtering
Status: Done

Milestone

0.8.11

Development

Successfully merging this pull request may close these issues.

Add filter for exhaustive switch-expression

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@Godin @nioncode @marchof
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.