Skip to content

Add Check Support for Java 21 Unnamed Variables & Patterns Syntax: New Check UnusedCatchParameterShouldBeUnnamed #15058

@mahfouz72

Description

@mahfouz72

child of #14942
violate the non-use of the catch parameters. They should be unnamed.


Config

$ cat config.xml 
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
        "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
    <module name="TreeWalker">
        <module name="UnusedCatchParameterShouldBeUnnamed"/>
    </module>
</module>

Example

 public class Test {
    void test(Object obj) {
        try {
            int x = 1 / 0;
        } catch (Exception e) {   // violation
            System.out.println("error");
        }
        try {
            int x = 1 / 0;
        } catch (Exception _) {
            System.out.println("error");
        }
    }
}

Expected Output

$ java -jar checkstyle-10.19.0-all.jar -c config.xml Test.java 
Starting audit...
[ERROR] D:\Test.java:5:28:Unused catch parameter should be unnamed [UnusedCatchParameterShouldBeUnnamed]
Audit done.
Checkstyle ends with 1 errors.

How we could suppress violations in this check for (ignore|ignored) naming convention

#15058 (comment)

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions