Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 254848

Summary: [compiler] Importing deprecated classes is a warning, even if not used in non-deprecated code
Product: [Eclipse Project] JDT Reporter: Martin Probst <mail>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: minor    
Priority: P3 CC: Olivier_Thomann, philippe_mulet
Version: 3.4.1   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard: stalebug

Description Martin Probst CLA 2008-11-11 04:51:46 EST
Build ID: M20080911-1700

Steps To Reproduce:
Write a class that uses deprecated classes/interfaces somewhere, but only in one old method, e.g.:

import java.io.StringBufferInputStream; // <--- WARNING
import java.io.StringReader;

class MyClass {
  // bad code
  @Deprecated
  void doFoo(StringBufferInputStream bleh) { ... }
  // good code
  void doFoo(StringReader sr) { ... }
}

Note that MyClass here is a commonly used, large interface, where only a miniscule amount of code is deprecated (well, at least imagine it ;-)).

Now the JDT compiler flags a warning for the deprecated import ("the type ... is deprecated"). I don't want to add a SuppressWarnings("deprecated") tag to the class, as most of the code is not using deprecated code, and I would like to get appropriate warnings.

AFAIK, JDT doesn't have an option to disable this warning. This hampers the evolution of classes and interfaces. Also, I don't quite know why there is a specific warning for the import - code that actually uses the deprecated type will get a warning anyways, and unused imports are a different warning. It does not seem very helpful in general (to me, at least). 

More information:
Comment 1 Philipe Mulet CLA 2008-11-13 13:01:23 EST
One thing you could do is to discard the import and qualify the type name inside the deprecated code area.
Comment 2 Philipe Mulet CLA 2008-11-13 13:01:55 EST
or use an on demand import instead.
Comment 3 Philipe Mulet CLA 2008-11-13 13:44:24 EST
re: comment 1
I meant:

import java.io.StringReader;

class MyClass {
  // bad code
  @Deprecated
  void doFoo(java.io.StringBufferInputStream bleh) { ... }
  // good code
  void doFoo(StringReader sr) { ... }
}
Comment 4 Martin Probst CLA 2008-11-16 10:42:24 EST
Yes, those workarounds will probably work.

But my question is more to the point: why does the compiler flag a warning here at all? If code uses the deprecated class, the warning will be on the code. So this is just a detraction from the real problem in the code, or a superfluous warning if everything else uses the correct @Deprecated tags.
Comment 5 Eclipse Genie CLA 2020-03-05 17:35:14 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.