Re: Extending checkstyle to detect objetc comparison with == operator.

"Oliver Burn" <[email protected]> Fri, 26 Sep 2008 08:42:10 +1000
Newsgroups gmane.comp.java.audit.checkstyle.user
Message-ID <[email protected]>
I would recommend using FindBugs for these types of bugs.

On Fri, Sep 26, 2008 at 01:14, <[email protected]> wrote:

> Hello,
>
> I am currently working on a project which was partly developped by java
> newbies and we encountered several bugs which had for root cause object
> comparison using == instead of .equals().
>
> Those objects (1 class + 1 subclass) are from a cached repository so they
> would work for unit testing but would start showing erratic behavior after
> cache invalidations.
>
> I wanted to use checkstyle on this project to mainly improve code quality
> and enforce standards but i would also like to extend it to detect those
> erroneous comparisons.
>
> Bad code would look like
>
> RepositoryItem item1 = ...
> RepositoryItem item2 = ...
>
> if (item1 == item2) {
>    doCriticalStuff();
> }
>
> Is it possible to extend checkstyle to detect this ?
>
> I have started working on a check class (largely inspired from
> StringLiteralEquality) but i am unsure on how to check the instance type. I
> have the AST items ready (aka. getFirstChild() +
> getFirstChild().nextSibling() ). But i dont know how to proceed to detect
> that they are instances of RepositoryItem or one of their subclass.
>
> I would appreciate any help on this matter.
>
>
> Thanks in advance,
> Benoit.
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Checkstyle-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

_______________________________________________
Checkstyle-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user