Deprecated Interface Methods Create Unavoidable Warnings

We are ramping up on Java and testing. We decided to create a null/almost null implementation of an interface in order to have a UnitTestDelegator to pass as a stand-in argument.

The interface we needed to implement has a deprecated method. We *must* implement the deprecated method in order to satisfy the compiler.

However, now that we've implemented the deprecated method, the compiler issues a warning which we can't find a way to turn off.

Given that we have been practicing strictest warnings completely clean for 7 years in Perl, C, and C++, this makes my skin crawl!

Am I wrong in thinking that this is a JavaDesignFlaw?

-- JeffBay

You turn it off by marking it deprecated as well. e.g:

   /** @deprecated */
   public void aDeprecatedMethod() { throw new RuntimeException("This is no longer supported"); }

The bummer comes when the whole interface is deprecated... You can still avoid the message about the method, but I haven't found a way to avoid the message about the class.


That's what all four of us expected, and that's exactly what one of us tried. Now three of us have looked at the code and tried it again, and this is what we see:

The specific example with the example is (so to spake):

 public class FakeHttpServletResponse? implements HttpServletResponse? {

// ... every method that is in the HttpServletResponse? class is implemented as an empty stub. // the deprecated methods are the only ones that cause a problem, of course:

/** @deprecated */ public String encodeUrl(String url) { return null; } }

The former code causes this exact method (not the superclass) to be listed in the javadoc as a "deprecated method", but the compiler still falls all over itself to tell me about this extremely important warning. If you take off the /** @deprecated */ line, it still compiles exactly the same, except that the javadoc generated files no longer list it as deprecated. Same exact warning from javac, however.

What gives?

javac on a linux server. I don't know offhand any more information about the java landscape, though I can provide details if needed to diagnose the problem. Perhaps we should take this to email? My WikiName has a mailto for me...

-- JeffBay

How about this for a solution?

We create an abstract class that implements the problematic deprecated method, place that abstract class compiled into a jar file, destroy the source, and always extend the abstract class instead of the original class.

If this sounds as stupid to you as it does to me, tell me what is wrong with our "/** deprecated */" line above. We've tried moving the characters around, adding the recommended comments, etc... nothing seems to work.

It is particularly annoying because java*doc* understands it in generating the deprecated list, but java*c* complains about it!

-- JeffBay

I do it like this (taken from a real class, implementing javax.ejb.SessionContext?):

    /**
     * @deprecated
     */
    public java.util.Properties getEnvironment() {
        throw new NotYetImplementedException?();
    }

Works like a charm for me. WinNT, java(c) 1.3. Like I said, I only get real problems when I have a deprecated class.

Do you invoke the deprecated method anywhere? This will trigger the warning (unless it's invoked from another deprecated method, of course). -- RobertWatkins.

So, the only difference between what you have and what I had was that it didn't throw an exception. So, I implemented a NotYetImplementedException? static inner class, and threw that from within my deprecated method. Still get the build warning.

How exactly is this all supposed to work? Obviously javac isn't talking to the javadoc processor, since they disagree on whether there is a problem here. Is javac supposed to be looking for the method to throw an exception or something? It's supposed to work exactly as described... as sick as it is (and I almost consider this a language flaw in itself, though the Java crew have their reasons) the javac compiler actually does parse javadoc comments, just to look for the @deprecated tag. As to why it's not working on your system... I really don't know. WorksForMe. Try a different compiler, maybe build on an NT box, and see if it's just a compiler bug?

-- JeffBay

This is driving me crazy! DeprecatedInterfaceMethodsCreateUnavoidableWarningsPleaseHelp?!

-- JeffBay


This is not want you want. Bug 4460939 in the JavaBugDatabase wants to add a tag which overrides making a warning.


If you don't like deprecation warnings, disable them. Simple enough.


I think I found the solution, I was having this problem as well using jdk1.4.0. When compiling the same code with jdk1.4.2, I don't get deprecation warnings for implementing deprecated methods of an interface. I haven't turned deprecation warnings off... I'd suggest upgrading your jdk.

    -Brian Vaughan


Comments on Page:


EditText of this page (last edited October 5, 2014) or FindPage with title or text search