-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Closed
Description
https://checkstyle.org/checks/annotation/suppresswarningsholder.html#SuppressWarningsHolder
/var/tmp $ javac YOUR_FILE.java
#[[PLACE YOUR OUTPUT HERE]]
/var/tmp $ cat config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="SuppressWarningsFilter"/>
<module name="TreeWalker">
<module name="HiddenField"/>
<module name="SuppressWarningsHolder">
<property name="aliasList" value="com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheck=LocalVariableHidesMemberVariable"/>
</module>
</module>
</module>
/var/tmp $ cat YOUR_FILE.java
package test;
class Test {
private int a;
void withOriginal() {
@SuppressWarnings({"hiddenfield"})
int a = 1;
}
void withAlias() {
@SuppressWarnings("LocalVariableHidesMemberVariable")
int a = 1;
}
}
/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-X.XX-all.jar -c config.xml YOUR_FILE.java
Starting audit...
[ERROR] r:\!spikes\!Checkstyle\alias\src\main\java\test\Test.java:6:9: 'a' hides a field. [HiddenField]
Audit done.
Checkstyle ends with 1 errors.
And variant 2:
/var/tmp $ javac YOUR_FILE.java
#[[PLACE YOUR OUTPUT HERE]]
/var/tmp $ cat config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="SuppressWarningsFilter"/>
<module name="TreeWalker">
<module name="HiddenField"/>
<module name="SuppressWarningsHolder">
<!-- <property name="aliasList" value="com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheck=LocalVariableHidesMemberVariable"/> -->
</module>
</module>
</module>
/var/tmp $ cat YOUR_FILE.java
package test;
class Test {
private int a;
void withOriginal() {
@SuppressWarnings({"hiddenfield"})
int a = 1;
}
void withAlias() {
@SuppressWarnings("LocalVariableHidesMemberVariable")
int a = 1;
}
}
/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-X.XX-all.jar -c config.xml YOUR_FILE.java
Starting audit...
[ERROR] r:\!spikes\!Checkstyle\alias\src\main\java\test\Test.java:10:9: 'a' hides a field. [HiddenField]
Audit done.
Checkstyle ends with 1 errors.
So, I either have one @SuppressWarnings
working or another, not both at the same time.
Documentation says that aliasList
property specifies aliases.
Alias means another name
. So, it should not replace existing name, but add another one.