Re: checking for null Noob question

2010-07-31 Thread Jérémy DE ROYER
I won't do the second one because you could see a NullPointerException. Is it 
your question ?

Jérémy

Le 31 juil. 2010 à 14:05, Theodore Petrosky a écrit :

 
 Why does this work:
 
 public String dueDateTypeLetter() {
   
 if (this.dueDateType() == null || this.dueDateType().equals(N)) {
 return ;
 }
 return this.dueDateType();
 }
 
 and this doesn't
 
 public String dueDateTypeLetter() {
   
 if (this.dueDateType().equals(N) || this.dueDateType() == null) {
 return ;
 }
 return this.dueDateType();
 }
 
 obviously the difference is the order of checking in the 'if' statement...
 
 I don't really care that I must check in a specific order... It just took me 
 time to understand that the order was important.
 
 Ted
 
 
 
 
 
 
 ___
 Do not post admin requests to the list. They will be ignored.
 Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/webobjects-dev/jeremy.deroyer%40ingencys.net
 
 This email sent to jeremy.dero...@ingencys.net

 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: checking for null Noob question

2010-07-31 Thread Theodore Petrosky
Yes... I was asking 'Why?' is there a NullPointerException with number 2...

Ted


--- On Sat, 7/31/10, Jérémy DE ROYER jeremy.dero...@ingencys.net wrote:

 From: Jérémy DE ROYER jeremy.dero...@ingencys.net
 Subject: Re: checking for null Noob question
 To: Theodore Petrosky tedp...@yahoo.com
 Cc: webobjects-dev@lists.apple.com
 Date: Saturday, July 31, 2010, 8:07 AM
 I won't do the second one because you
 could see a NullPointerException. Is it your question ?
 
 Jérémy
 
 Le 31 juil. 2010 à 14:05, Theodore Petrosky a écrit :
 
  
  Why does this work:
  
  public String dueDateTypeLetter() {
          
  if (this.dueDateType() == null ||
 this.dueDateType().equals(N)) {
  return ;
  }
  return this.dueDateType();
  }
  
  and this doesn't
  
  public String dueDateTypeLetter() {
          
  if (this.dueDateType().equals(N) ||
 this.dueDateType() == null) {
  return ;
  }
  return this.dueDateType();
  }
  
  obviously the difference is the order of checking in
 the 'if' statement...
  
  I don't really care that I must check in a specific
 order... It just took me time to understand that the order
 was important.
  
  Ted
  
  
  
  
  
  
  ___
  Do not post admin requests to the list. They will be
 ignored.
  Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
  Help/Unsubscribe/Update your Subscription:
  http://lists.apple.com/mailman/options/webobjects-dev/jeremy.deroyer%40ingencys.net
  
  This email sent to jeremy.dero...@ingencys.net
 
 



 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: checking for null Noob question

2010-07-31 Thread Jérémy DE ROYER
So the answer is :
- if the object is null, as, in the second test, your use the method 'equals' 
on this object (null)  NullPointerException

On the first test, as you first test if the object is null, you can't have a 
NullPointerException

Hope this help,

Jérémy

Le 31 juil. 2010 à 14:09, Theodore Petrosky a écrit :

 Yes... I was asking 'Why?' is there a NullPointerException with number 2...
 
 Ted
 
 
 --- On Sat, 7/31/10, Jérémy DE ROYER jeremy.dero...@ingencys.net wrote:
 
 From: Jérémy DE ROYER jeremy.dero...@ingencys.net
 Subject: Re: checking for null Noob question
 To: Theodore Petrosky tedp...@yahoo.com
 Cc: webobjects-dev@lists.apple.com
 Date: Saturday, July 31, 2010, 8:07 AM
 I won't do the second one because you
 could see a NullPointerException. Is it your question ?
 
 Jérémy
 
 Le 31 juil. 2010 à 14:05, Theodore Petrosky a écrit :
 
 
 Why does this work:
 
 public String dueDateTypeLetter() {
 
 if (this.dueDateType() == null ||
 this.dueDateType().equals(N)) {
 return ;
 }
 return this.dueDateType();
 }
 
 and this doesn't
 
 public String dueDateTypeLetter() {
 
 if (this.dueDateType().equals(N) ||
 this.dueDateType() == null) {
 return ;
 }
 return this.dueDateType();
 }
 
 obviously the difference is the order of checking in
 the 'if' statement...
 
 I don't really care that I must check in a specific
 order... It just took me time to understand that the order
 was important.
 
 Ted
 
 
 
 
 
 
 ___
 Do not post admin requests to the list. They will be
 ignored.
 Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/webobjects-dev/jeremy.deroyer%40ingencys.net
 
 This email sent to jeremy.dero...@ingencys.net
 
 
 
 
 



 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: checking for null Noob question

2010-07-31 Thread Farrukh Ijaz
Or do the following trick:

if(!N.equals(this.dueDateType()) {
return this.dueDateType(); 
}
return ;

Or failsafe operation:

if(!(this.dueDateType()+).equals(N)) {
return this.dueDateType(); 
}
return ;

But all above are applicable to strings only. For other types, you always need 
to follow the LTR precedence.

Or use try-catch-finally block. Do the wrong things in try, fix the wrong in 
catch and use finally for final work. ;)

Farrukh

Sent from my iPad

On 31-Jul-2010, at 3:13 PM, Jérémy DE ROYER jeremy.dero...@ingencys.net wrote:

 So the answer is :
 - if the object is null, as, in the second test, your use the method 
 'equals' on this object (null)  NullPointerException
 
 On the first test, as you first test if the object is null, you can't have a 
 NullPointerException
 
 Hope this help,
 
 Jérémy
 
 Le 31 juil. 2010 à 14:09, Theodore Petrosky a écrit :
 
 Yes... I was asking 'Why?' is there a NullPointerException with number 2...
 
 Ted
 
 
 --- On Sat, 7/31/10, Jérémy DE ROYER jeremy.dero...@ingencys.net wrote:
 
 From: Jérémy DE ROYER jeremy.dero...@ingencys.net
 Subject: Re: checking for null Noob question
 To: Theodore Petrosky tedp...@yahoo.com
 Cc: webobjects-dev@lists.apple.com
 Date: Saturday, July 31, 2010, 8:07 AM
 I won't do the second one because you
 could see a NullPointerException. Is it your question ?
 
 Jérémy
 
 Le 31 juil. 2010 à 14:05, Theodore Petrosky a écrit :
 
 
 Why does this work:
 
 public String dueDateTypeLetter() {
 
 if (this.dueDateType() == null ||
 this.dueDateType().equals(N)) {
 return ;
 }
 return this.dueDateType();
 }
 
 and this doesn't
 
 public String dueDateTypeLetter() {
 
 if (this.dueDateType().equals(N) ||
 this.dueDateType() == null) {
 return ;
 }
 return this.dueDateType();
 }
 
 obviously the difference is the order of checking in
 the 'if' statement...
 
 I don't really care that I must check in a specific
 order... It just took me time to understand that the order
 was important.
 
 Ted
 
 
 
 
 
 
 ___
 Do not post admin requests to the list. They will be
 ignored.
 Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/webobjects-dev/jeremy.deroyer%40ingencys.net
 
 This email sent to jeremy.dero...@ingencys.net
 
 
 
 
 
 
 
 
 ___
 Do not post admin requests to the list. They will be ignored.
 Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/webobjects-dev/farrukh.ijaz%40fuegodigitalmedia.com
 
 This email sent to farrukh.i...@fuegodigitalmedia.com
 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: checking for null Noob question

2010-07-31 Thread Paul Hoadley
Hi Ted,

The '||' operator is a 'short circuit' operator, and it evaluates the left-hand 
side first.  Assume this.dueDateType() returns null, then in this case:

On 31/07/2010, at 9:35 PM, Theodore Petrosky wrote:

 if (this.dueDateType() == null || this.dueDateType().equals(N)) {

the expression on the left-hand side is true, and the right-hand side is never 
evaluated (because its value won't affect the value of the whole expression).  
That is, it short circuits and you avoid a NullPointerException.  In this 
case:

 if (this.dueDateType().equals(N) || this.dueDateType() == null) {

this.dueDateType().equals(N) is evaluated, and you get a NullPointerException.

 I don't really care that I must check in a specific order... It just took me 
 time to understand that the order was important.

The order is only important to the extent that the LHS is always evaluated, and 
the RHS is only evaluated if the LHS is false.  So in this case, where you're 
doing a null check specifically to avoid an exception, yes it needs to be on 
the LHS.

http://en.wikipedia.org/wiki/Short-circuit_evaluation


-- 
Paul.

http://logicsquad.net/


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: checking for null Noob question

2010-07-31 Thread Theodore Petrosky
Thanks, this was exactly the information I was looking for.

Ted


--- On Sat, 7/31/10, Paul Hoadley pa...@logicsquad.net wrote:

 From: Paul Hoadley pa...@logicsquad.net
 Subject: Re: checking for null Noob question
 To: Theodore Petrosky tedp...@yahoo.com
 Cc: webobjects-dev@lists.apple.com
 Date: Saturday, July 31, 2010, 8:46 AM
 Hi Ted,
 
 The '||' operator is a 'short circuit' operator, and it
 evaluates the left-hand side first.  Assume
 this.dueDateType() returns null, then in this case:
 
 On 31/07/2010, at 9:35 PM, Theodore Petrosky wrote:
 
  if (this.dueDateType() == null ||
 this.dueDateType().equals(N)) {
 
 the expression on the left-hand side is true, and the
 right-hand side is never evaluated (because its value won't
 affect the value of the whole expression).  That is, it
 short circuits and you avoid a NullPointerException. 
 In this case:
 
  if (this.dueDateType().equals(N) ||
 this.dueDateType() == null) {
 
 this.dueDateType().equals(N) is evaluated, and you get a
 NullPointerException.
 
  I don't really care that I must check in a specific
 order... It just took me time to understand that the order
 was important.
 
 The order is only important to the extent that the LHS is
 always evaluated, and the RHS is only evaluated if the LHS
 is false.  So in this case, where you're doing a null
 check specifically to avoid an exception, yes it needs to be
 on the LHS.
 
 http://en.wikipedia.org/wiki/Short-circuit_evaluation
 
 
 -- 
 Paul.
 
 http://logicsquad.net/
 
 
 



 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: checking for null Noob question

2010-07-31 Thread Mike Schrag
+1 for N.equals(whatever) to prevent NPEs

Sent from my iPhone

On Jul 31, 2010, at 9:44 AM, Theodore Petrosky tedp...@yahoo.com wrote:

 Thanks, this was exactly the information I was looking for.
 
 Ted
 
 
 --- On Sat, 7/31/10, Paul Hoadley pa...@logicsquad.net wrote:
 
 From: Paul Hoadley pa...@logicsquad.net
 Subject: Re: checking for null Noob question
 To: Theodore Petrosky tedp...@yahoo.com
 Cc: webobjects-dev@lists.apple.com
 Date: Saturday, July 31, 2010, 8:46 AM
 Hi Ted,
 
 The '||' operator is a 'short circuit' operator, and it
 evaluates the left-hand side first.  Assume
 this.dueDateType() returns null, then in this case:
 
 On 31/07/2010, at 9:35 PM, Theodore Petrosky wrote:
 
 if (this.dueDateType() == null ||
 this.dueDateType().equals(N)) {
 
 the expression on the left-hand side is true, and the
 right-hand side is never evaluated (because its value won't
 affect the value of the whole expression).  That is, it
 short circuits and you avoid a NullPointerException. 
 In this case:
 
 if (this.dueDateType().equals(N) ||
 this.dueDateType() == null) {
 
 this.dueDateType().equals(N) is evaluated, and you get a
 NullPointerException.
 
 I don't really care that I must check in a specific
 order... It just took me time to understand that the order
 was important.
 
 The order is only important to the extent that the LHS is
 always evaluated, and the RHS is only evaluated if the LHS
 is false.  So in this case, where you're doing a null
 check specifically to avoid an exception, yes it needs to be
 on the LHS.
 
 http://en.wikipedia.org/wiki/Short-circuit_evaluation
 
 
 -- 
 Paul.
 
 http://logicsquad.net/
 
 
 
 
 
 
 ___
 Do not post admin requests to the list. They will be ignored.
 Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com
 
 This email sent to msch...@pobox.com
 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: checking for null Noob question

2010-07-31 Thread Steve Peery
Just to avoid confusion and the NullPointerException, I would suggest this:

{
   if (this.dueDateType() == null) {
return ;
   }
   else if (this.dueDateType().equals(N)) {
return ;
   }
   return this.dueDateType();
}

or this:

{
   if (this.dueDateType() != null) {
  if (!this.dueDateType().equals(N)) {
 return this.dueDateType();
  }
   }
   return ;
}

Steve


On Jul 31, 2010, at 8:13 AM, Jérémy DE ROYER wrote:

 So the answer is :
 - if the object is null, as, in the second test, your use the method 
 'equals' on this object (null)  NullPointerException
 
 On the first test, as you first test if the object is null, you can't have a 
 NullPointerException
 
 Hope this help,
 
 Jérémy
 
 Le 31 juil. 2010 à 14:09, Theodore Petrosky a écrit :
 
 Yes... I was asking 'Why?' is there a NullPointerException with number 2...
 
 Ted
 
 
 --- On Sat, 7/31/10, Jérémy DE ROYER jeremy.dero...@ingencys.net wrote:
 
 From: Jérémy DE ROYER jeremy.dero...@ingencys.net
 Subject: Re: checking for null Noob question
 To: Theodore Petrosky tedp...@yahoo.com
 Cc: webobjects-dev@lists.apple.com
 Date: Saturday, July 31, 2010, 8:07 AM
 I won't do the second one because you
 could see a NullPointerException. Is it your question ?
 
 Jérémy
 
 Le 31 juil. 2010 à 14:05, Theodore Petrosky a écrit :
 
 
 Why does this work:
 
 public String dueDateTypeLetter() {
 
 if (this.dueDateType() == null ||
 this.dueDateType().equals(N)) {
 return ;
 }
 return this.dueDateType();
 }
 
 and this doesn't
 
 public String dueDateTypeLetter() {
 
 if (this.dueDateType().equals(N) ||
 this.dueDateType() == null) {
 return ;
 }
 return this.dueDateType();
 }
 
 obviously the difference is the order of checking in
 the 'if' statement...
 
 I don't really care that I must check in a specific
 order... It just took me time to understand that the order
 was important.
 
 Ted
 
 
 
 
 
 
 ___
 Do not post admin requests to the list. They will be
 ignored.
 Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/webobjects-dev/jeremy.deroyer%40ingencys.net
 
 This email sent to jeremy.dero...@ingencys.net
 
 
 
 
 
 
 
 
 ___
 Do not post admin requests to the list. They will be ignored.
 Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/webobjects-dev/speery%40me.com
 
 This email sent to spe...@me.com

 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com