JDK-4963930 : New lint option to warn of unused import statements.
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P5
  • Status: Closed
  • Resolution: Won't Fix
  • OS: solaris_9,windows_xp
  • CPU: x86,sparc
  • Submitted: 2003-12-04
  • Updated: 2024-04-12
  • Resolved: 2014-06-05
Related Reports
Relates :  
Description
Lately I've been writing code that uses pieces from numerous packages.
I've got a large collection of boilerplate import statements that I tend
to pick and choose from.  If I miss one, the compiler of course lets me know.
But if I have unused import statements, the compiler of course doesn't care.

For readability, I'd like to remove the superfluous imports.  Gee it would
sure be swell if the compiler had a lint flag that would trigger a warning
about them.

Comments
The point is not that IDE cannot do this. The point is that Javac could do it much more easily and faster since it has the symbol table right there. It would be nice to leverage Javac to make other tools, such as IDE's, faster.
05-06-2014

In the ten years since Neal judged this a good idea, IDEs have stepped in to solve this problem. As far as I know, all major IDEs will flag unused imports and offer automated bulk-fix; certainly IntelliJ does this (and has for ten years.)
05-06-2014

We do not believe that static analysis of this sort is the proper focus for the Java compiler. The set of static checks like this that could be performed is infinite; further, many of these are already handled by existing static analysis tools like FindBugs, PMD, or CheckStyle. To the extent we devote resources to adding new lint warnings, we prefer to focus on things that *only* can be done in javac or provide a more significant payback.
05-06-2014

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
17-07-2004

PUBLIC COMMENTS ...
17-07-2004

EVALUATION Good idea ###@###.### 2003-12-04
04-12-2003