Detecting likely wrong setter/getter methods

Example code (actually some custom rectangle class somewhere, having minX, minY, maxX, maxY fields + getters + setters):
----

    public int getMaxY() {
        return maxX;
    }

----

Questions:
1) Is there an inspection that will find this?
2) I remember an inspection that would report "'yyy' should probably not be passed for parameter 'xxx'", however, I cannot find it anymore.
(I think it's the one referenced in this post: http://benzilla.galbraiths.org/2007/01/18/i-love-intelligent-tools/)
What's the name of this inspection?

Thanks,
-tt
2 comments
Comment actions Permalink

It's called "Suspicious variable/parameter name combination" (in category probable bugs).
But it doesn't highlight suspicious method name/return variable combinations :(

However it warns about the same mistake in the setter:
public void setMaxY(int maxY) {
maxX = maxY;
}

Looks like an enhancement request for Bas ;)

Taras Tielkes wrote:

Example code (actually some custom rectangle class somewhere, having minX, minY, maxX, maxY fields + getters + setters):
----

public int getMaxY() {
return maxX;
}
---- Questions:1) Is there an inspection that will find this?2) I remember an inspection that would report "'yyy' should probably not be passed for parameter 'xxx'", however, I cannot find it anymore.(I think it's the one referenced in this post: http://benzilla.galbraiths.org/2007/01/18/i-love-inte
lligent-tools/)What's the name of this inspection? Thanks,-tt
---
Original message URL: http://www.jetbrains.net/devnet/message/5228608#5228608

0
Comment actions Permalink

I'll file an enhancement request in JIRA.

Would it make sense to have a more generic inspection that checks getters/setters, and flags them if they assign/query from a field not corresponding to their names? A precondition would be that a field matching the getter/setter name is _also_ present, in order to reduce false positives.

0

Please sign in to leave a comment.