Skip to content

[java] SwitchStmtsShouldHaveDefault false-positive with Java 14 switch non-fallthrough branches #2806

@boris-petrov

Description

@boris-petrov

Affects PMD Version:

All, including 6.28.0.

Rule: SwitchStmtsShouldHaveDefault

Description:

	public String foo(String foo) {
		switch (foo) {
			case "=" -> foo = "eq";
			case "!=" -> foo = "ne";
			default -> throw new IllegalArgumentException();
		}
		return foo + 'a';
	}

This causes a SwitchStmtsShouldHaveDefault warning.

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]

Gradle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions