Can findbugs detect unused public methods

后端 未结 8 1617
死守一世寂寞
死守一世寂寞 2020-12-19 04:45

Is it possible to detect unused methods in a source tree using FindBugs? I see some posts on SO where users are claiming to do that, some others asking how to do this in FB

相关标签:
8条回答
  • 2020-12-19 05:32

    as a member of the FindBugs team I can tell you that unfortunately FindBugs does not do this. If you search through the bug patterns on our website, the only mentions of "unused" detectors is for unused fields.

    0 讨论(0)
  • 2020-12-19 05:33

    The best approach (to me) to find candidates for unused methods is to use coverage tools, like emma.

    Instrument you application, use it excessivly and examine the emma logs - methods that not have been used during the session may be unused and you can use your favourite IDE (eclipse, ...) to examine the unvisited methods call hierarchies.

    I doubt, that find bugs or any other code analyser can really detect unused methods, because methods may be

    • called by other libraries (for all non-private methods)
    • called remotely
    • invoked through reflection API (even private methods, technically spoken)
    0 讨论(0)
提交回复
热议问题