JDK-8026357 : Add warnings for unused variables and methods
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • Submitted: 2013-10-11
  • Updated: 2014-06-05
  • Resolved: 2014-06-05
Related Reports
Relates :  
Description
Please add -Xlint warnings for unused local variables, unused parameters, unused private fields and unused private methods. Such warnings can be used by Auditing tools, hooking into JSR199 Javac, to offer fixes to remove any unused variables/methods.
See also JDK-4963930 which asks for an -Xlint warning to detect unused imports.


Comments
The point is not that IDE's cannot do this. The point is that Javac could do this much faster. It would be nice to be able to leverage Javac to make other tools, such as IDE's, faster.
05-06-2014

Most, if not all, IDEs offer this feature already (IntelliJ certainly does.) Similarly, FindBugs will report dead local stores (writes, but no subsequent reads, to locals) as well as fields that are never used (or written but never read) and methods that are never called.
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

In addition there should be warnings about unused private classes.
03-06-2014

There would need to be a way to disable such warnings (using @SuppressWarnings, etc.) since Java method can be exclusively called from native code outside of the view of javac and sometimes methods are but in classes for calling under a debugger.
15-10-2013