Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

How to use Java 13 features with Java 8- Part 3 (How to find deprecated methods)

1 min read

A Java deprecated method is one that should not be used because it is going to be removed (and often there is a better, more modern alternative). It is a correction to the API. In the past, Java did not remove any methods and kept backwards compatibility with everything. But with the new modular and non-monolithic JDK, this has changed. Oracle has removed methods in the JDK from Java9 onwards as part of the tidy up for Jigsaw.

So it is probably time to have a general strategy to move away from deprecated methods. So how do you identify where your code uses deprecated methods?

In previous versions of Java, messages would be displayed at compile time. Here are examples from IDEA and NetBeans IDE

deprecated methods warning

This is now so familiar, my conscious mind just ignores it (and I suspect I am not the only one!).

From Java9 however, there is a new command line tool which will also give this information call jdeprscan. This has lots of interesting options to show deprecated methods. Running with default values shows the deprecated methods we use in our code:-

jdeprscan build-jpedal-1.0-SNAPSHOT.jar
Jar file build-jpedal-1.0-SNAPSHOT.jar:
class org/jpedal/examples/viewer/gui/swing/SwingMouseListener uses deprecated method java/awt/event/InputEvent::getModifiers()I 
class org/jpedal/objects/acroforms/creation/ListListener uses deprecated method javax/swing/JList::getSelectedValues()[Ljava/lang/Object; 
class org/jpedal/objects/acroforms/creation/SwingFormFactory uses deprecated method javax/swing/JList::getSelectedValues()[Ljava/lang/Object; 
class org/jpedal/examples/viewer/gui/swing/SwingMenuItems uses deprecated class java/awt/Event 
class org/jpedal/examples/viewer/gui/swing/AnnotationEditor$DragListener uses deprecated method java/awt/event/InputEvent::getModifiers()I 

There some really interesting additional methods also such as -for-removal or -release which allow more precise details on the deprecated methods.

So an action for us to update these usages of deprecated methods with alternatives. And if you want to ensure your code continues to work cleanly on later versions of Java as well as Java8, now is the time to experiment with JDeprscan and update that old codebase!

 

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2019. All rights reserved.