1

I see that using deprecation annotation isn't forcing/warning if user doesn't add link to the new item:

The ability to deprecate a class, method, or member field solves the problem. Java supports two mechanisms for deprecation: and an annotation, (supported starting with J2SE 5.0) and a Javadoc tag (supported since 1.1). Existing calls to the old API continue to work, but the annotation causes the compiler to issue a warning when it finds references to deprecated program elements. The Javadoc tag and associated comments warn users against using the deprecated item and tell them what to use instead

Also specify in @deprecated oracle docs

The @deprecated description in the first sentence should at least tell the user when the API was deprecated and what to use as a replacement.

But the replacement isn't forced or warns about its absent

For example Apache's StringEscapeUtils doesn't specify replacement in several cases

public static final String escapeJava(String input)

Deprecated.

Escapes the characters in a String using Java String rules....

Or direct to other deprecated methods

public static final String escapeXml(String input)

Deprecated.

use escapeXml10(java.lang.String) or escapeXml11(java.lang.String) instead.

Is there any way/tool that can warns if it doesn't state what is my (valid) substitute solution for deprecated method/class?

Side note: docs also offer how to ignore a missing replacement:

If the member has no replacement, the argument to @deprecated should be "No replacement".

Community
  • 1
  • 1
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • Are the methods on `StringEscapeUtils` actually specifying they are deprecated, or are they just inheriting the annotation from the class (where the alternative is stated). – Andy Turner Sep 27 '18 at 05:45
  • @AndyTurner It's not consistent, I see for example `@Deprecated public static final String escapeXml(String input) {` – Ori Marko Sep 27 '18 at 05:46
  • I suspect that is historical: it looks like the method was deprecated in favour of the other methods in the same class; then the class was deprecated after. – Andy Turner Sep 27 '18 at 06:02
  • @AndyTurner it's just an example of missing link to a new item on deprecated method. Can I create a warning (eclipse/sonar/...) in such cases? – Ori Marko Sep 27 '18 at 06:05
  • other tools are available, but this could be achieved with Google's Error Prone. Interestingly, there is [a check for the other way round](http://errorprone.info/bugpattern/DepAnn) (`@deprecated` in Javadoc, but no `@Deprecated` in the code). I can ask the team why it's not enforced both ways. – Andy Turner Sep 27 '18 at 06:05
  • @AndyTurner just to verify, I'm asking about missing **replacement link** of deprecated method – Ori Marko Sep 27 '18 at 07:51
  • there is no guarantee that there is a replacement for a method. You might simply be saying "don't use this, it's broken", for example `Thread.stop()`. Or there might be more than 1, as in the example here. – Andy Turner Sep 27 '18 at 09:05

0 Answers0