Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,6 @@ public final boolean isMethodUseDeprecated(MethodBinding method, Scope scope,
// inside same unit - no report
if (scope.isDefinedInSameUnit(method.declaringClass)) return false;

// non explicit use and non explicitly deprecated - no report
if (!isExplicitUse &&
(method.modifiers & ClassFileConstants.AccDeprecated) == 0) {
return false;
}

// if context is deprecated, may avoid reporting
if (!scope.compilerOptions().reportDeprecationInsideDeprecatedCode && scope.isInsideDeprecatedCode()) return false;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,76 @@ public class Test {
""";
runner.runWarningTest();
}
// Test for issue #4553 - calling deprecated method through inherited interface
public void testInheritedInterfaceDeprecatedMethod() {
this.runNegativeTest(
new String[] {
"p1/BaseInterface.java",
"package p1;\n" +
"public interface BaseInterface {\n" +
" /** @deprecated */\n" +
" void deprecatedMethod();\n" +
"}\n",

"p2/DerivedInterface.java",
"package p2;\n" +
"import p1.BaseInterface;\n" +
"public interface DerivedInterface extends BaseInterface {\n" +
"}\n",

"p3/Caller.java",
"package p3;\n" +
"import p2.DerivedInterface;\n" +
"public class Caller {\n" +
" void test(DerivedInterface obj) {\n" +
" obj.deprecatedMethod(); // Should warn about deprecated method\n" +
" }\n" +
"}\n"
},
"----------\n" +
"1. WARNING in p3\\Caller.java (at line 5)\n" +
" obj.deprecatedMethod(); // Should warn about deprecated method\n" +
" ^^^^^^^^^^^^^^^^\n" +
"The method deprecatedMethod() from the type BaseInterface is deprecated\n" +
"----------\n"
);
}
// Test for issue #4553 - @SuppressWarnings should be necessary for deprecated method through inherited interface
public void testInheritedInterfaceDeprecatedMethodWithSuppressWarnings() {
Map customOptions = new HashMap();
customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING);
customOptions.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR);
this.runNegativeTest(
new String[] {
"p1/BaseInterface.java",
"package p1;\n" +
"public interface BaseInterface {\n" +
" /** @deprecated */\n" +
" void deprecatedMethod();\n" +
"}\n",

"p2/DerivedInterface.java",
"package p2;\n" +
"import p1.BaseInterface;\n" +
"public interface DerivedInterface extends BaseInterface {\n" +
"}\n",

"p3/Caller.java",
"package p3;\n" +
"import p2.DerivedInterface;\n" +
"public class Caller {\n" +
" @SuppressWarnings(\"deprecation\")\n" +
" void test(DerivedInterface obj) {\n" +
" obj.deprecatedMethod(); // SuppressWarnings should be necessary\n" +
" }\n" +
"}\n"
},
null,
customOptions,
"", // Should compile without errors - SuppressWarnings is valid
JavacTestOptions.DEFAULT
);
}
public static Class testClass() {
return DeprecatedTest.class;
}
Expand Down