Can findbugs detect unused public methods

后端 未结 8 1622
死守一世寂寞
死守一世寂寞 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条回答
  •  Happy的楠姐
    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)

提交回复
热议问题