RFR(m): 8145464: jdeprscan - java deprecation scanner (command-line tool)
Stuart Marks
stuart.marks at oracle.com
Fri Jul 22 00:16:08 UTC 2016
Hi all,
Please review the code for "jdeprscan", the new Java deprecation scanner
command-line tool. This is part of JEP 277, Enhanced Deprecation.
The only deprecation warnings provided up until now are those from by javac,
emitted when compiling Java source code. If you don't have the source code, or
if it's inconvenient to recompile, it's hard to find out what deprecated APIs a
class might be using. The jdeprscan tool will scan class files for uses of APIs
that are deprecated in the JDK. (A future enhancement will allow scanning for
deprecated APIs from other class libraries.)
For example, consider the following source file, which compiles without warnings
on JDK 8:
-----
package depr.example;
import java.math.BigDecimal;
public class Foo {
BigDecimal x(BigDecimal num) {
Runtime.getRuntime().traceInstructions(true);
return num.divide(BigDecimal.TEN, BigDecimal.ROUND_HALF_DOWN);
}
}
-----
It's possible to run jdeprscan over the compiled class file in order to detect
uses of APIs newly deprecated in Java 9:
-----
$ jdeprscan -cp build/classes depr.example.Foo
class depr/example/Foo uses method java/lang/Runtime traceInstructions (Z)V
deprecated FOR REMOVAL
class depr/example/Foo uses method java/math/BigDecimal divide
(Ljava/math/BigDecimal;I)Ljava/math/BigDecimal; deprecated
-----
The output is somewhat cryptic and could stand to be cleaned up, but the
information is all there.
Here's the webrev:
http://cr.openjdk.java.net/~smarks/reviews/8145464/webrev.0/
User-level documentation is currently a markdown file in the source code:
http://cr.openjdk.java.net/~smarks/reviews/8145464/webrev.0/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/readme.md.html
(Eventually, of course, this will be migrated to the right location.)
Most of the changes are in the langtools repository, shown by the webrev above.
There is a small change to the jdk repository to build a launcher for jdeprscan.
The patch for that is appended below.
Thanks,
s'marks
diff -r b211a52a7439 make/launcher/Launcher-jdk.jdeps.gmk
--- a/make/launcher/Launcher-jdk.jdeps.gmk Wed Jul 20 08:32:07 2016 -0700
+++ b/make/launcher/Launcher-jdk.jdeps.gmk Thu Jul 21 14:09:38 2016 -0700
@@ -36,3 +36,9 @@
CFLAGS := -DEXPAND_CLASSPATH_WILDCARDS \
-DNEVER_ACT_AS_SERVER_CLASS_MACHINE, \
))
+
+$(eval $(call SetupBuildLauncher, jdeprscan, \
+ MAIN_CLASS := com.sun.tools.jdeprscan.Main, \
+ CFLAGS := -DEXPAND_CLASSPATH_WILDCARDS \
+ -DNEVER_ACT_AS_SERVER_CLASS_MACHINE, \
+))
More information about the jdk9-dev
mailing list