8033421: @SuppressWarnings("deprecation") does not work when overriding deprecated method

Fri, 07 Feb 2014 21:43:33 +0100

author
jlahoda
date
Fri, 07 Feb 2014 21:43:33 +0100
changeset 2553
191d1aecdf68
parent 2552
02370b1748eb
child 2554
e76105e91c16

8033421: @SuppressWarnings("deprecation") does not work when overriding deprecated method
Summary: When the overrides deprecated method warning is being reported, need to do that in the lint context of the method.
Reviewed-by: vromero

src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
test/tools/javac/warnings/suppress/Overridden.java file | annotate | diff | comparison | revisions
test/tools/javac/warnings/suppress/Overridden.out file | annotate | diff | comparison | revisions
test/tools/javac/warnings/suppress/OverriddenSuppressed.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Tue Aug 19 20:42:56 2014 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Feb 07 21:43:33 2014 +0100
     1.3 @@ -1715,7 +1715,12 @@
     1.4  
     1.5          // Warn if a deprecated method overridden by a non-deprecated one.
     1.6          if (!isDeprecatedOverrideIgnorable(other, origin)) {
     1.7 -            checkDeprecated(TreeInfo.diagnosticPositionFor(m, tree), m, other);
     1.8 +            Lint prevLint = setLint(lint.augment(m));
     1.9 +            try {
    1.10 +                checkDeprecated(TreeInfo.diagnosticPositionFor(m, tree), m, other);
    1.11 +            } finally {
    1.12 +                setLint(prevLint);
    1.13 +            }
    1.14          }
    1.15      }
    1.16      // where
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/warnings/suppress/Overridden.java	Fri Feb 07 21:43:33 2014 +0100
     2.3 @@ -0,0 +1,16 @@
     2.4 +/**
     2.5 + * @test /nodynamiccopyright/
     2.6 + * @bug 8033421
     2.7 + * @summary Check that \\@SuppressWarnings works properly when overriding deprecated method.
     2.8 + * @build VerifySuppressWarnings
     2.9 + * @compile/ref=Overridden.out -XDrawDiagnostics -Xlint:deprecation Overridden.java
    2.10 + * @run main VerifySuppressWarnings Overridden.java
    2.11 + */
    2.12 +
    2.13 +public class Overridden implements Interface {
    2.14 +    public void test() { }
    2.15 +}
    2.16 +
    2.17 +interface Interface {
    2.18 +    @Deprecated void test();
    2.19 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/warnings/suppress/Overridden.out	Fri Feb 07 21:43:33 2014 +0100
     3.3 @@ -0,0 +1,2 @@
     3.4 +Overridden.java:11:17: compiler.warn.has.been.deprecated: test(), Interface
     3.5 +1 warning
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/warnings/suppress/OverriddenSuppressed.java	Fri Feb 07 21:43:33 2014 +0100
     4.3 @@ -0,0 +1,38 @@
     4.4 +/*
     4.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.
    4.11 + *
    4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.15 + * version 2 for more details (a copy is included in the LICENSE file that
    4.16 + * accompanied this code).
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License version
    4.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.21 + *
    4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    4.23 + * or visit www.oracle.com if you need additional information or have any
    4.24 + * questions.
    4.25 + */
    4.26 +
    4.27 +/**
    4.28 + * @test
    4.29 + * @bug 8033421
    4.30 + * @summary Check that \\@SuppressWarnings works properly when overriding deprecated method.
    4.31 + * @compile -Werror -Xlint:deprecation OverriddenSuppressed.java
    4.32 + */
    4.33 +
    4.34 +public class OverriddenSuppressed implements Interface {
    4.35 +    @SuppressWarnings("deprecation")
    4.36 +    public void test() { }
    4.37 +}
    4.38 +
    4.39 +interface Interface {
    4.40 +    @Deprecated void test();
    4.41 +}

mercurial