Warning message “uses or overrides a deprecated API” encountered during code compilation

What you should do is to do what the Warning messages say. Recompile that class with the -Xlint:deprecation option. The compiler will then tell you what deprecated API you are using or overriding.

How to do that?


Once you have identified the API that is causing the problem, there are three approaches to “resolving” the error.

  1. You can read the javadocs for the deprecated API to find out why it is deprecated. Then based on what the javadocs say, and the context, you need to work out a way to replace your code’s use of the deprecated element with something better.

  2. You can use the @SuppressWarnings("deprecation") annotation to tell the compiler to “be quiet” about it.

    This is generally a bad idea:

    • The deprecated API may be removed in a future release, and that will prevent your code from running when you upgrade. (You would be advised to review the products policy on removal of deprecated APIs.)

    • The deprecated API may have fundamental flaws that make your application unreliable in some circumstances.

    Injudicious suppression of these warnings is just creating technical dept that you or your successors will have to resolve in the future.

  3. If the deprecation warning was due to a change in a Java SE itself or in a 3rd-party API that you are using, you could “resolve” it by rolling back to the version that didn’t show the warnings. This is even a worse idea than the previous one. By rolling back, you are just allowing the technical dept to accumulate.


(For this particular example, my guess is that the OP was using one of the deprecated methods in the Thread class:

  • countStackFrames()
  • destroy()
  • pause()
  • resume()
  • stop()
  • stop(Throwable)
  • suspend()

These methods are either unreliable, unsafe or both, and you are strongly advised not to use them. Read this explanation: “Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?“.)

Leave a Comment