Is there a way in netbeans to show which methods etc are never used?

Maximilian

Lifer
Feb 8, 2004
12,604
15
81
I think i may have a few redundant setters/getters and other stuff, ive noticed netbeans will warn me if a variable/value is never used, is there any way to show which methods are not called during a run of a program?

I know this could lead to me deleting something valuable because if a method isnt called that dosent mean it will never be called but i can at least look at it and see what if anything it actually does :)
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,695
4,658
75
I don't know about NetBeans, but have you tried PMD?
 

BrightCandle

Diamond Member
Mar 15, 2007
4,762
0
76
Never used is a surprisingly hard problem. A method might be reachable in a variety of ways and determining true reachability is fuzzy in a lot of cases. All this analysis can be made worse by the use of reflection which means that pretty much any method could get called without any direct or obvious possible indirection.

Take for example a method that calls a method 'aMethod' on an interface 'IFace'. If I have two implementations of IFace both with an aMethod, but nowhere in the code do I see either implementation created does that mean that aMethod is or is not called? One of the two implementations is extremely likely to get called if the code calling onto IFace is ever called but even this simple example isn't possible to reason about because its determined at runtime.

I have been working on a solution to this problem for a while and I am likely to release some software that helps sometime this year, which is a bit cleverer than just statically called.
 

dwell

pics?
Oct 9, 1999
5,185
2
0
If you're worried about dead code just make sure you use private functions judiciously. If a function is public in a language that supports dynamic binding either use it or lose it.
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
If the method is private, then netbeans will let you know if it is never used. However, public methods are not checked for usage for the reasons BrightCandle has pointed out.