Beta Draft: 2017-03-28

jdeprscan

You use the jdeprscan tool as a static analysis tool that scans a jar file (or some other aggregation of class files) for uses of deprecated API elements.

Synopsis

jdeprscan [ options ]{dir|jar|class}

For more information about the options used with the jdeprscan command, see Options for the jdeprscan Command

Description

A common pitfall during development is that dependent classes cannot be found. This occurs especially when scanning individual classes or class files. The result is a series of error messages of the form:

      error: cannot find class ...  

If this occurs, the class path must be adjusted to include all dependent classes.

The jdeprscan tool is a static analysis tool provided by the JDK that scans a jar file (or some other aggregation of class files) for uses of deprecated API elements. Note that the deprecated APIs identified by jdeprscan only come from Java SE.

Options for the jdeprscan Command

jdeprscan command scans each argument for usages of deprecated APIs. The arguments can be a:

  • Directory

  • JAR file,

  • Class name

  • Class file

The class name the class name should use dot (.) as a separator. For example:

java.lang.Thread

For nested classes, the $ separator character should be used. For example:

java.lang.Thread$State

A class file can also be named. For example:

build/classes/java/lang/Thread$State.class

The following options are available:

--class-path PATH

Provides a search path for resolution of dependent classes

--for-removal

Limits scanning or listing to APIs that are deprecated for removal. Cannot be used with a release value of 6, 7, or 8.

--full-version

Prints out the full version string of the tool.

—h or --help

Prints out a full help message.

—l or --list

Prints out the set of deprecated APIs. No scanning is done, so no directory, jar, or class arguments should be provided.

--release 6|7|8|9

Specifies the Java SE release that provides the set of deprecated APIs for scanning.

—v or --verbose

Enables additional message output during processing.

--version

Prints out the abbreviated version string of the tool.

Example of Output

The following is an example of output from running the jdeprscan command:

class org/apache/commons/math3/util/MathUtils uses deprecated method java/lang/Double::<int>(D)V

This indicates that the class org.apache.commons.math3.util.MathUtils uses a deprecated API. Note that the class name is specified using the slash-separated binary name as described in JVMS 4.2.1. This is the form used internally in class files.

The deprecated API it uses is a method on the java.lang.Double class. Notice the slash-separated name in the output.

The name of the deprecated method is <init>, which is a special name that means that the method is actually a constructor. The other special name is <clinit>, which indicates a class static initializer.

Other methods are just listed by method name. Following the method name is the argument list and return type:

(D)V

This indicates that it takes a single double value (a primitive) and returns void. The argument and return types can become cryptic. For example, another line of output is:

 class org/apache/commons/math3/util/Precision uses deprecated method java/math/BigDecimal::setScale(II)Ljava/math/BigDecimal;   

The deprecated method is on class java.math.BigDecimal, and the method is setScale(). In this case, the (II) means that it takes two int arguments.The Ljava/math/BigDecimal; after the parentheses means that it returns a reference to java.math.BigDecimal.

This format is specified in JVMS sections 4.3.2 "Field Descriptors" and 4.3.3 "Method Descriptors." It's cryptic but well-defined, and should be familiar to anyone working at the level of the JVM and class files.