Here's the hashCode()
method that Eclipse kindly generated for me:
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}
When I run findbugs on this, it complains about the last line:
Method ...hashCode() stores return result in local before immediately returning it [Scariest(2), Normal confidence]
Who is right here? Findbugs or Eclipse? Is this dodgy?
I cannot for the life of me see why this is anything for findbugs to get upset about. The code is perfectly clear; storing it in a local before returning it doesn't make it harder to read or harder to maintain; and unless the compiler is very badly written then it won't make any difference to performance either.
And yet this is categorised as Scariest!
Am I missing something?
(Clearly the code could be simplified in some respects, and it's come out that way because as far as Eclipse is concerned, there might have been other fields going into the hash function. But it's specifically the issue of storing a value and then immediately returning it that I'm asking about here, because that's what findbugs is complaining about.)