Here's another entry along the same lines as 'try without catch in the JDK'. After making some enhancements to PMD's unused parameter rule I ran it on the JDK source to see what turned up. This rule only checks private methods since public methods frequently have unused parameters due to interface implementation requirements. Anyhow, here are some notes:
java.net.URI
has a resolvePath method that take three params, the third of which,absolute
, is unused. It's a little strange because the method seems to sort out whether or not the path is absolute or not on its own: This method is only used once and it's passed a calculated value in the third parameter, so removing that parameter from it and from the method invocation would probably save a few cycles.java.io.FileSystem
has an odd getBooleanProperty method that takes a String parameterprop
and a boolean parameter. Strangely, the String parameter is unused and in the spot where I'd expect it to be used there's this: This method also uses this wordy construct: Which could be boiled down to this:PMD's SimplifyBooleanReturns rule will find those cases; good times.
java.security.Security
has a doGetImpl method that takes a Stringalgorithm
as the first parameter; this parameter is unused. It looks a little weird since the method throws both NoSuchAlgorithmException and InvalidAlgorithmParameterException, but anyhow, the algorithm name seems to be encoded in the second parameter which is a String namedtype
.
Another example that turns up in a few places is related to serialization. Some classes declare the private writeObject
method but they just throw an exception rather than using the ObjectOutputStream parameter. Might be worth adding an exception to the rule for this method name since that's effectively a false positive...
For much more along these lines, get the PMD book!