| Summary: | @SuppressWarnings("deprecation") does not suppress deprecation warning on imports | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Willian Mitsuda <wmitsuda> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | VERIFIED DUPLICATE | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | ||
| Version: | 3.1.1 | ||
| Target Milestone: | 3.2 M5 | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
*** This bug has been marked as a duplicate of 124522 *** Reopen to close as dup og bug 123522 and not 124522. *** This bug has been marked as a duplicate of 123522 *** This bug was marked as a DUPL of bug#123522, which was VERIFIED against I20060215-0010. However, this bug still happens on I20060215-0010, so I'm reopening it. Put back as duplicate as you need to put your @SuppressWarnings("deprecation") on class declaration and not on main method only.
So, following test case does not produce any deprecation warning:
package com.mycompany.myapp;
import com.mycompany.DeprecatedClass;
@SuppressWarnings("deprecation")
public class MyClass {
public static void main(String[] args) {
DeprecatedClass c = new DeprecatedClass();
....
}
}
*** This bug has been marked as a duplicate of 123522 ***
Ok, my fault... Sorry! |
Consider the following sample code: ------ DeprecatedClass.java: package com.mycompany; @Deprecated public class DeprecatedClass { ... } ------ MyClass.java: package com.mycompany.myapp; import com.mycompany.DeprecatedClass; public class MyClass { public static void main(String[] args) { DeprecatedClass c = new DeprecatedClass(); .... } } ------ In MyClass.java, the Eclipse compiler warns about DeprecatedClass being, er, deprecated ;-) Suppose I want intentionally to use DeprecatedClass, because it is legacy code and I don't have a drop-in replacement solution, but I don't want the deprecation warning in this method (or class), so I annotate it with @SuppressWarnings: package com.mycompany.myapp; import com.mycompany.DeprecatedClass; public class MyClass { @SuppressWarnings("deprecation") public static void main(String[] args) { DeprecatedClass c = new DeprecatedClass(); .... } } and the warning disappears from main method, but it still remains in the import clause! Yes, I know that @SupressWarnings is not applicable to import statements, but I think the compiler should not warn a deprecated class in the import statement if the code block where it is used is annotated with @SuppressWarnings("deprecation")