This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 199451 - Warning Hint for unused Method Parameters missing
Summary: Warning Hint for unused Method Parameters missing
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.0
Hardware: PC Windows Vista
: P3 normal with 7 votes (vote)
Assignee: Svata Dedic
Depends on:
Reported: 2011-06-16 08:48 UTC by bht
Modified: 2017-11-24 00:56 UTC (History)
3 users (show)

See Also:
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description bht 2011-06-16 08:48:20 UTC
public class Test {
    public void doSomething(String neverUsed){// Does not show being unused
    	String neverUsedEither;// Shows as being unused, ok
Comment 1 Jan Lahoda 2011-06-16 08:57:34 UTC
Yes, this was disabled after 6.0 for non-private methods, as way too often there is nothing that could reasonably be done about this: e.g. the method may be called from a lot of places. It was too annoying to see unused parameters that couldn't practically be fixed.
Comment 2 bht 2011-06-18 03:31:18 UTC
My apologies if I misunderstand this.

I do understand that the _name_ of a public method where no caller could be found is not highlighted because it would not be safe to do that.

However if a public method does not contain any code within it that uses its own parameters, then I don't understand why one would not want these parameters to be highlighted. Methods having too many parameters is a very common problem to solve.

There are of course scenarios for multiple classes implementing the same interfaces where their methods don't use all interface method parameters. Still I would want to know this in such cases because it helps me improve the interfaces by using overloading etc..

I had a practical situation where I was maintaining a legacy system, struggling to eliminate dead code. The productivity enhancing value of this missing feature would definitely outweigh the slight annoyance of hints that one potentially cannot fix.

Do you have a reference to the issue where this feature was removed?
Comment 3 bht 2012-01-21 03:56:32 UTC
I see why it is preferred to not show this. Some frameworks have interfaces with many methods where only some of them are used in implementations.
Could this be made an optional feature?
Comment 4 angryboywilty 2012-04-02 07:13:18 UTC
Stating that 'way too often' this warning is displayed in an older code base ignores the fact that the warning is really useful in new or developing code. Taking the warning away was robbing Peter to pay Paul - one issue solved, new one created. Why not add it as a selectable warning hint, so that people could _choose_ whether or not to show these warnings for public methods?
Comment 5 crazyjavahacking 2012-04-18 17:48:46 UTC
Please implement a way to turn it for public methods as well.
Comment 6 alied 2012-04-18 18:12:30 UTC
(In reply to comment #3)
> I see why it is preferred to not show this. Some frameworks have interfaces
> with many methods where only some of them are used in implementations.
> Could this be made an optional feature?

I think there is a misinterpretation here. This issue is about unused parameters within a function. I agree that can be very handy.

What others are talking about is about unused non-private functions, which is not of much sense (unless you define some context, say, project, opened project), and still I don't see much of a gain for it.
Comment 7 angryboywilty 2012-04-19 07:13:26 UTC
(In reply to comment #6)
> > Some frameworks have interfaces with many methods where only some of them are used in implementations.
> I think there is a misinterpretation here...
> What others are talking about is about unused non-private functions...

I don't think anyone here is talking about unused non-private methods (which you cannot really do anything about other than marking them obsolete). In the comment by bht, I believe 'some of them' is referring to method parameters, not the methods themselves.

Certain other IDEs provide some extra SuppressWarnings flags such as "unused" and "unusedArgument", which can be used for more fine-grained control (as well as giving the option to turn the warnings on/off globally). That seems to be the ideal solution, although I would settle for the ability to toggle the warnings globally.
Comment 8 leoquijano 2012-05-01 19:36:34 UTC
(*I think this is about parameters and not private method hints*)

Even though there are good reasons to minimize the number of parameters in a method's design, there are a lot of frameworks that include extra params by default. When implementing a method for an API (either via Interface or dynamic calls), you're forced to add those parameters to keep compatibility.

For some languages that's mandatory (meaning the linker won't link your method if you don't include all required parameters), for some others it's optional, but still you want to include all parameters as a reference.

I don't think the hint should be removed, just made more fire-grained. Most of the time, local unused variables are always trash, while unused method parameters are intended to be there. So it would be nice to have the option to select whether or not we want those warnings.

Just my 2 cents :)
Comment 9 Jan Lahoda 2012-05-01 20:47:07 UTC
First, let me give you a few examples where it is often inconvenient to mark the non-private method parameters unused:
1. a method that overrides/implements other method: there may be other overriders/implementors that use the specific parameter, and in such a case the highlighting is simply a noise that cannot be resolved in vast majority of cases. This relates to the usecase described in #c2, but seems to me that for that usecase it would much more beneficial to have a warning that would say "no known overrider/implementor is using this parameter" (but that is a feature request, not a defect).
2. a method is overridden and the overrider is using the parameter. E.g.:
public void commandPerformed(Command cmd) {
    //the subclass may override this method to be informed about an event
Again, the highlighting in this case is only some noise.

Given this, I am not in favor of changing the default behavior. I am not against introducing an option, although that does bring several problems to solve:
-where to place such an option? Might be possible to (ab-)use the Tools/Options/Editors/Hint tab for that, even though that brings a few trouble itself (e.g. the "Show As" combo normally does not contain "Unused" item, but it probably would have to for these semi-hints).
-what are all the required options? Should it be possible to disable the highlighting for overriding method, overridable methods, public/protected/package private methods?
-it should probably be possible to suppress the highlighting using @SuppressWarnings - not unsolvable, but I don't think there is a precedent for that in the highlighting area (as opposed to the warning area).
Comment 10 _ gtzabari 2013-01-15 18:00:38 UTC
Updated milestone since 7.0.1 has already been released.
Comment 11 Zom-B 2014-10-07 07:13:18 UTC
I just found some bugs in my code after I loaded it into Eclipse, and it told me there were unused parameters (yes, not just forgot to use a parameter but used the wrong one somewhere). Then I got back to NB 8.0 and tried to enable the same warning, only to find out that it's a long standing feature request.
Comment 12 adamstyl 2017-04-26 11:14:33 UTC
Is there any progress on that? There are some of us out there that we consider unused parameters in methods (public or private) a code smell.
Comment 13 ChrisLE 2017-10-01 02:26:11 UTC
This feature is a must have, it is implemented for JS but not for Java. It is not about the caller of the function with the unused param, it is about the unused param, that is never used inside the function, thats why it is unused.