Skip to content

Throwable values used as switch argument are considered unused #4260

@sviperll

Description

@sviperll

Apache NetBeans version

Apache NetBeans 14

What happened

Throwable values used as arguments of a switch-statement (with pattern matching) are considered unused.

Throwable cause = ...; // WARNING: unused local variable
switch (cause) {
    case IOException ex -> throw ex;
    case Throwable ex -> throw new UnexpectedException(ex);
}

similar behavior is observed when throwable-returning methods are used:

try {
} catch (InvocationTargetException ex) {
    switch (ex.getCause()) { // WARNING: the result of throwable returning method is ignored
        case IOException ex -> throw ex;
        case Throwable ex -> throw new UnexpectedException(ex);
    }
}

I expect that no warning are generated in both cases, because the values are actually used.

How to reproduce

Any code written with JDK 18 that follows the pattern described above forces NetBeans to generate warnings/hints.

Did this work correctly in an earlier version?

No

Operating System

Fedora 34

JDK

JDK 18

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

The problem is stable and occurs all the time.

Are you willing to submit a pull request?

No

Code of Conduct

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Java[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)hintskind:bugBug report or fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions