On Wed, 2 Feb 2022 12:06:39 GMT, David Holmes <dhol...@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":

        // 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

Reply via email to