Since Checkstyle 5.0
@Deprecated
and the Javadoc tag
@deprecated
are both present when either of them is present.
Both ways of flagging deprecation serve their own purpose. The @Deprecated annotation is used for compilers and development tools. The @deprecated javadoc tag is used to document why something is deprecated and what, if any, alternatives exist.
In order to properly mark something as deprecated both forms of deprecation should be present.
Package deprecation is an exception to the rule of always using the javadoc tag and annotation to deprecate. It is not clear if the javadoc tool will support it or not as newer versions keep flip-flopping on if it is supported or will cause an error. See JDK-8160601. The deprecated javadoc tag is currently the only way to say why the package is deprecated and what to use instead. Until this is resolved, if you don't want to print violations on package-info, you can use a filter to ignore these files until the javadoc tool faithfully supports it. An example config using SuppressionSingleFilter is:
<!-- required till https://bugs.openjdk.org/browse/JDK-8160601 --> <module name="SuppressionSingleFilter"> <property name="checks" value="MissingDeprecatedCheck"/> <property name="files" value="package-info\.java"/> </module>
name | description | type | default value | since |
---|---|---|---|---|
violateExecutionOnNonTightHtml | Control when to print violations if the Javadoc being examined by this check violates the tight html rules defined at Tight-HTML Rules. | boolean | false |
8.24 |
To configure the check:
<module name="Checker"> <module name="TreeWalker"> <module name="MissingDeprecated"/> </module> </module>
Example:
class Example1 { @Deprecated public static final int MY_CONST = 13; // ok /** This javadoc is missing deprecated tag. */ // violation below '@deprecated Javadoc tag with description.' @Deprecated public static final int COUNTER = 10; /** * @deprecated * <p></p> */ @Deprecated public static final int NUM = 123456; // ok /** * @deprecated * <p> */ @Deprecated public static final int CONST = 12; // ok }
To configure the check such that it prints violation messages if tight HTML rules are not obeyed
<module name="Checker"> <module name="TreeWalker"> <module name="MissingDeprecated"> <property name="violateExecutionOnNonTightHtml" value="true"/> </module> </module> </module>
Example:
class Example2 { @Deprecated public static final int MY_CONST = 13; // ok /** This javadoc is missing deprecated tag. */ // violation below '@deprecated Javadoc tag with description.' @Deprecated public static final int COUNTER = 10; /** * @deprecated * <p></p> */ @Deprecated public static final int NUM = 123456; // ok /** * @deprecated * <p> // violation, 'Unclosed HTML tag found: p' */ @Deprecated public static final int CONST = 12; }
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.annotation