1JDEPRSCAN(1) JDK Commands JDEPRSCAN(1)
2
3
4
6 jdeprscan - static analysis tool that scans a jar file (or some other
7 aggregation of class files) for uses of deprecated API elements
8
10 jdeprscan [options] {dir|jar|class}
11
12 options
13 See Options for the jdeprscan Command
14
15 dir|jar|class
16 jdeprscan command scans each argument for usages of deprecated
17 APIs. The arguments can be a:
18
19 • dir: Directory
20
21 • jar: JAR file
22
23 • class: Class name or class file
24
25 The class name should use a dot (.) as a separator. For exam‐
26 ple:
27
28 java.lang.Thread
29
30 For nested classes, the dollar sign $ separator character should
31 be used. For example:
32
33 java.lang.Thread$State
34
35 A class file can also be named. For example:
36
37 build/classes/java/lang/Thread$State.class
38
40 The jdeprscan tool is a static analysis tool provided by the JDK that
41 scans a JAR file or some other aggregation of class files for uses of
42 deprecated API elements. The deprecated APIs identified by the jde‐
43 prscan tool are only those that are defined by Java SE. Deprecated
44 APIs defined by third-party libraries aren't reported.
45
46 To scan a JAR file or a set of class files, you must first ensure that
47 all of the classes that the scanned classes depend upon are present in
48 the class path. Set the class path using the --class-path option de‐
49 scribed in Options for the jdeprscan Command. Typically, you would use
50 the same class path as the one that you use when invoking your applica‐
51 tion.
52
53 If the jdeprscan can't find all the dependent classes, it will generate
54 an error message for each class that's missing. These error messages
55 are typically of the form:
56
57 error: cannot find class ...
58
59 If these errors occur, then you must adjust the class path so that it
60 includes all dependent classes.
61
63 The following options are available:
64
65 --class-path path
66 Provides a search path for resolution of dependent classes.
67
68 path can be a search path that consists of one or more directo‐
69 ries separated by the system-specific path separator. For exam‐
70 ple:
71
72 • Linux and OS X:
73
74 --class-path /some/directory:/another/different/dir
75
76 Note:
77
78 On Windows, use a semicolon (;) as the separator instead of a
79 colon (:).
80
81 • Windows:
82
83 --class-path \some\directory;\another\different\dir
84
85 --for-removal
86 Limits scanning or listing to APIs that are deprecated for re‐
87 moval. Can't be used with a release value of 6, 7, or 8.
88
89 --full-version
90 Prints out the full version string of the tool.
91
92 --help or -h
93 Prints out a full help message.
94
95 --list or -l
96 Prints the set of deprecated APIs. No scanning is done, so no
97 directory, jar, or class arguments should be provided.
98
99 --release 6|7|8|9
100 Specifies the Java SE release that provides the set of deprecat‐
101 ed APIs for scanning.
102
103 --verbose or -v
104 Enables additional message output during processing.
105
106 --version
107 Prints out the abbreviated version string of the tool.
108
110 The JAR file for this library will be named something similar to com‐
111 mons-math3-3.6.1.jar. To scan this JAR file for the use of deprecated
112 APIs, run the following command:
113
114 jdeprscan commons-math3-3.6.1.jar
115
116 This command produces several lines of output. For example, one line
117 of output might be:
118
119 class org/apache/commons/math3/util/MathUtils uses deprecated method java/lang/Double::<init>(D)V
120
121 Note:
122
123 The class name is specified using the slash-separated binary name as
124 described in JVMS 4.2.1. This is the form used internally in class
125 files.
126
127 The deprecated API it uses is a method on the java.lang.Double class.
128
129 The name of the deprecated method is <init>, which is a special name
130 that means that the method is actually a constructor. Another special
131 name is <clinit>, which indicates a class static initializer.
132
133 Other methods are listed just by their method name. Following the
134 method name is the argument list and return type:
135
136 (D)V
137
138 This indicates that it takes just one double value (a primitive) and
139 returns void. The argument and return types can become cryptic. For
140 example, another line of output might be:
141
142 class org/apache/commons/math3/util/Precision uses deprecated method java/math/BigDecimal::setScale(II)Ljava/math/BigDecimal;
143
144 In this line of output, the deprecated method is on class ja‐
145 va.math.BigDecimal, and the method is setScale(). In this case, the
146 (II) means that it takes two int arguments. The Ljava/math/BigDecimal;
147 after the parentheses means that it returns a reference to ja‐
148 va.math.BigDecimal.
149
151 You can use jdeprscan relative to the previous three JDK releases. For
152 example, if you are running JDK 9, then you can check against JDK 8, 7,
153 and 6.
154
155 As an example, look at this code snippet:
156
157 public class Deprecations {
158 SecurityManager sm = new RMISecurityManager(); // deprecated in 8
159 Boolean b2 = new Boolean(true); // deprecated in 9
160 }
161
162 The complete class compiles without warnings in JDK 7.
163
164 If you run jdeprscan on a system with JDK 9, then you see:
165
166 $ jdeprscan --class-path classes --release 7 example.Deprecations
167 (no output)
168
169 Run jdeprscan with a release value of 8:
170
171 $ jdeprscan --class-path classes --release 8 example.Deprecations
172 class example/Deprecations uses type java/rmi/RMISecurityManager deprecated
173 class example/Deprecations uses method in type java/rmi/RMISecurityManager deprecated
174
175 Run jdeprscan on JDK 9:
176
177 $ jdeprscan --class-path classes example.Deprecations
178 class example/Deprecations uses type java/rmi/RMISecurityManager deprecated
179 class example/Deprecations uses method in type java/rmi/RMISecurityManager deprecated
180 class example/Deprecations uses method java/lang/Boolean <init> (Z)V deprecated
181
182
183
184JDK 17 2021 JDEPRSCAN(1)