RFR: 8281057: Fix doc references to overriding in JLS
David Holmes
david.holmes at oracle.com
Wed Feb 2 13:39:38 UTC 2022
On 2/02/2022 10:46 pm, Pavel Rappo wrote:
> On Wed, 2 Feb 2022 12:06:39 GMT, David Holmes <dholmes at openjdk.org> wrote:
>
>>> While looking into guts of javadoc comment inheritance, I noticed that a number of places in JDK seem to confuse JLS 8.4.6.** with JLS 8.4.8.**.
>>>
>>> Granted, "8.4.6 Method Throws" tangentially addresses overriding. However, I believe that the real target should be "8.4.8. Inheritance, Overriding, and Hiding" and its subsections.
>>
>> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java line 1793:
>>
>>> 1791: }
>>> 1792:
>>> 1793: // Error if static method overrides instance method (JLS 8.4.8.2).
>>
>> "overrides" should be "hides"
>
> Although you seem to be correct, the error messages and the code around operate using the term "override":
Ah yes, I can see now that "overrides" is (incorrectly) used all through
this code and even in the error messages. It is a subtle distinction.
Cheers,
David
-----
> // Error if static method overrides instance method (JLS 8.4.8.2).
> if ((m.flags() & STATIC) != 0 &&
> (other.flags() & STATIC) == 0) {
> log.error(TreeInfo.diagnosticPositionFor(m, tree),
> Errors.OverrideStatic(cannotOverride(m, other)));
> m.flags_field |= BAD_OVERRIDE;
> return;
> }
>
> // Error if instance method overrides static or final
> // method (JLS 8.4.8.1).
> if ((other.flags() & FINAL) != 0 ||
> (m.flags() & STATIC) == 0 &&
> (other.flags() & STATIC) != 0) {
> log.error(TreeInfo.diagnosticPositionFor(m, tree),
> Errors.OverrideMeth(cannotOverride(m, other),
> asFlagSet(other.flags() & (FINAL | STATIC))));
> m.flags_field |= BAD_OVERRIDE;
> return;
> }
>
>
> /**
> * compiler.err.override.static=\
> * {0}\n\
> * overriding method is static
> */
> public static Error OverrideStatic(Fragment arg0) {
> return new Error("compiler", "override.static", arg0);
> }
>
> Compiler folk, what do you think?
>
> -------------
>
> PR: https://git.openjdk.java.net/jdk/pull/7311
More information about the serviceability-dev
mailing list