Bug 63270 - Compiler Warning: Usage of Deprecated API
Summary: Compiler Warning: Usage of Deprecated API
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.0 RC1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-20 14:00 EDT by Simon Archer CLA
Modified: 2004-05-24 18:42 EDT (History)
0 users

See Also:


Attachments
Screen shot (232.54 KB, image/gif)
2004-05-21 11:13 EDT, Simon Archer CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Archer CLA 2004-05-20 14:00:41 EDT
Build: Eclipse 3.0 M8

The Java > Compiler preference page for "Unused Code" contains options to check 
for the usage of deprecated API.  The check box "Signal overriding or 
implementing deprecated methods" does not quite work as I would expect.  For 
example consider the following interface and implemnting class:

  public interface IFoo {
    /**
     * @deprecated
     */
    public void bar();
  }

  public class Foo implements IFoo {
    public void bar() {  // Necessary implementation of deprecated IFoo API
      // No-op
    }
  }

The compiler places a warning marker against the Foo method bar(), which must 
be implemented since the class is an implementor of the IFoo interface.  Of 
course failure to implement this method results in a compiler error.  I think 
that it is unreasonable for the compiler to warn about this, since there is no 
reasonable alternative.

Now consider the following additional type:

  public class Foo2 extends Foo {
    public void bar() {  // Extends the Foo class' implementation.
      super.bar();
    }
  }

In this case, the compiler does NOT complain about the bar() method, even 
though it is extending the Foo class' implementation of bar().  This is also 
true if the bar() method overrides (ie, does not call super) the Foo class' 
implementation of bar().  I believe that the compiler should be complaining in 
this situation, because an inherited deprecated method is getting 
used/implemented.
Comment 1 Philipe Mulet CLA 2004-05-21 08:23:18 EDT
Did you check the box "Signal overriding or implementing deprecated methods" ?
Comment 2 Philipe Mulet CLA 2004-05-21 09:32:31 EDT
Cannot reproduce. If the check box is unchecked, no warning is issued when 
overriding/implementing a deprecated method. By default it is off.

Concerning the other issue about 'super.bar();', a warning is correctly issued 
as expected.

Note that deprecation warnings are never issued for code inside the same unit. 
Is it what you did ?

Closing. Reopen if you can still reproduce it given my explanations.
Comment 3 Simon Archer CLA 2004-05-21 11:10:34 EDT
Yes, I did check "Signal overriding or implementing deprecated methods".  Yes, 
when this checkbox is unchecked a warning is not issues, which is the correct 
behavior.  No, my example contains multiple compilation units.  I shall attach 
a screen shot that clearly shows what I'm doing.  The problem I'm describing is 
when the checkbox is checked, and you are:

1.  Implementing an interface that contains a deprecated API.  This should 
NEVER result in a warning, since there is no alternative, but it always does.

2.  Overriding/extending a deprecated method in a superclass.  Whether the 
superclass method is itself deprecated, or an implementation of a deprecated 
interface API is not important.  This should ALWAYS result in a warning, but it 
never does.  I removed the call to super(), since that's not important and is 
probably a distraction.

Please see the attached screen shot.  Thanks.
Comment 4 Simon Archer CLA 2004-05-21 11:13:05 EDT
Created attachment 10956 [details]
Screen shot
Comment 5 Philipe Mulet CLA 2004-05-24 11:44:26 EDT
Simon, let me explain how this is meant to work.

> 1.  Implementing an interface that contains a deprecated API.  This should 
> NEVER result in a warning, since there is no alternative, but it always does.

We don't distinguish interface methods from any other (note that abstract 
methods from superclasses would be falling into the same category).
The fact it is mandated by the API is true, but still it doesn't preclude from 
flagging this as an issue. Maybe it is time to consider switching to a 
different replacement API instead ? We could further offer some 
differenciation in between overriding/implementing abstract methods, but we 
wanted to keep the number of options reasonable; especially since it should be 
used in combination with the other option for not reporting deprecation in 
deprecated code (see below).

> 2.Overriding/extending a deprecated method in a superclass.  Whether the 
> superclass method is itself deprecated, or an implementation of a deprecated 
> interface API is not important.  This should ALWAYS result in a warning, but 
> it never does.  I removed the call to super(), since that's not important 
> and is probably a distraction.


The method in Foo2 overrides a method from Foo which isn't deprecated, so no 
complaint is issued.
---

I think you should start using the option for not reporting deprecation inside 
deprecated code. I believe it will express you exactly what you want.

If you enable it, you will still see a warning against Foo, and none in Foo2. 

You can fix the warning in Foo by tagging the #bar() method as deprecated 
itself. This way, you acknowledged the fact you did override a deprecated 
method (for whatever reason), and propagate the deprecation flag to further 
dependents.

Now, you should see no warning on Foo, and a warning on Foo2, since it now 
overrides a deprecated method. You can repeat the process on Foo2, so as to 
propagate the deprecation tag.

Propagating the deprecation tag is a cleaner approach, since client code may 
not use the original method, and would never notice the deprecation in 
hierarchy: e.g. new Foo2().bar();

Closing since working as designed.


Comment 6 Simon Archer CLA 2004-05-24 12:48:33 EDT
Thanks Philippe for taking the time to explain this to me.  I really appreciate 
it.  Yes, the propagation of deprecation is the right thing to do, and it is 
this that I missed.  Thanks again.
Comment 7 Philipe Mulet CLA 2004-05-24 18:42:19 EDT
No problem, glad someone uses our advanced deprecation warnings <g>