Skip to content

Add Check Support for Java 21 Unnamed Variables & Patterns Syntax: SuppressWarnings #15062

@mahfouz72

Description

@mahfouz72

child #14942
I have read check documentation: https://checkstyle.org/checks/annotation/suppresswarnings.html
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words


Allows to specify what warnings that @SuppressWarnings is not allowed to suppress. You can also specify a list of TokenTypes that the configured warning(s) cannot be suppressed on.

I can use @SuppressWarnings on pattern variables. should the check have PATTERN_VARIABLE_DEF in the tokens


PS D:\CS\test> cat src/Test.java                                                
record ColoredPoint(int p, int x, int c) { }
record Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight) { }

public class Test {
    void test(Object obj) {
        if (obj instanceof ColoredPoint( @SuppressWarnings("") int _, _,_)) { } // should this be violation ?
        if (obj instanceof @SuppressWarnings("") Rectangle r) { } // should this be violation ?
        @SuppressWarnings("") int _ = 0; // violation
    }
}

PS D:\CS\test> cat config.xml                                                   
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
        "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
    <property name="charset" value="UTF-8"/>
    <module name="TreeWalker">
        <module name="SuppressWarnings">
        </module>
    </module>
</module>
PS D:\CS\test> java  -jar checkstyle-10.17.0-all.jar -c config.xml src/Test.java
Starting audit...
[ERROR] D:\CS\test\src\Test.java:8:27: The warning '' cannot be suppressed at this location. [SuppressWarnings]
Audit done.
Checkstyle ends with 1 errors.
PS D:\CS\test> 

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions