JDK-8160604 : distinguish between calling and subclassing/overriding a deprecated method
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.lang
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2016-06-29
  • Updated: 2018-09-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Description
javac may need to be changed in order to distinguish between **calling** a deprecated method and **subclassing/overriding** a deprecated method.

A suitable annotation that distinguishes these usages hasn't yet been proposed, but the need for it is forseeable.

Consider the following example. (Note that the deprecation syntax for this is merely a straw-man.)

====================
    public class A {
        @Deprecated
        public void foo() { }

        @Deprecated(OVERRIDE)
        public void bar() { }
    }

    class B {
        void x(A a) {
            a.foo();  // should issue a deprecation warning
            a.bar();  // should NOT issue a deprecation warning
        }
    }

    class C extends A {
        void y(A a) {
            a.foo();  // should issue a deprecation warning
            a.bar();  // should NOT issue a deprecation warning
        }

        void z() {
            super.foo();  // should this issue a deprecation warning?
            super.bar();  // should this issue a deprecation warning?

        @Override
        public void bar() {  // definitely should issue a deprecation warning
        }
    }
====================

The idea is that it should be possible to deprecate something from being subclassed and overridden, but to continue to allow ordinary calls to the method without warnings.

One way to look at this is that an override-deprecation announces intent to make a method final. This allows direct calls and calls through super but not overriding. In this model the only warning issued for bar() in the above example would be the override in class C.

Scala has some kind of override-deprecation annotation (need to dig up link). It might not be public though. The intent is as above, to make a method final in a future release.