Re: [Codenarc-developer] UnnecessaryEqualityWithNull rule
Brought to you by:
chrismair
From: Hamlet D. <ham...@ca...> - 2011-06-06 12:17:34
|
I think, as is currently stands, you are correct. For it to be useful we need to find things like: def x = 'x' def y = 'y' x = null if (y.equals(x)) { ... } Which we don't have yet (but at some point would be nice). ----- Original Message ----- > I prefer x == null, too. But that "preference" is already handled by > the ExplicitCallToEqualsMethod rule, right? > > I'm not sure I see the value in the UnnecessaryEqualityWithNull rule, > given how Groovy does let you call equals() on null. > > -----Original Message----- > From: Hamlet DArcy [mailto:ham...@ca...] > Sent: Monday, June 06, 2011 1:31 AM > To: Chris Mair > Cc: cod...@li... > Subject: Re: [Codenarc-developer] UnnecessaryEqualityWithNull rule > > I never thought of this scenario. > > However, isn't > x.equals(null) > and > x == null > the same thing? > > I'd prefer the latter. > > > ----- Original Message ----- > > > > > > > > > > The documentation for UnnecessaryEqualityWithNull says > > > > The expression object.equals(null) is always false and is > > unnecessary. > > > > The object.equals(null) comparison will always return false, since > > the object is not null. (If the object is null, the program will > > throw a NullPointerException). This is the basic contract of the > > equals() method. > > > > > > > > But this prints true in the GroovyConsole, rather than throwing a > > NPE: > > > > > > > > def x = null > > > > println x.equals(null) > > > > > > > > Any thoughts on what to do with this rule? > > ------------------------------------------------------------------------------ > > Simplify data backup and recovery for your virtual environment with > > vRanger. > > Installation's a snap, and flexible recovery options mean your data > > is safe, > > secure and there when you need it. Discover what all the cheering's > > about. > > Get your free trial download today. > > http://p.sf.net/sfu/quest-dev2dev2 > > _______________________________________________ > > Codenarc-developer mailing list > > Cod...@li... > > https://lists.sourceforge.net/lists/listinfo/codenarc-developer > > > > ------------------------------------------------------------------------------ > Simplify data backup and recovery for your virtual environment with > vRanger. > Installation's a snap, and flexible recovery options mean your data > is safe, > secure and there when you need it. Discover what all the cheering's > about. > Get your free trial download today. > http://p.sf.net/sfu/quest-dev2dev2 > _______________________________________________ > Codenarc-developer mailing list > Cod...@li... > https://lists.sourceforge.net/lists/listinfo/codenarc-developer > |