• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Ternary op + autoboxing + null value = NPE?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Ternary op + autoboxing + null value = NPE?


  • Subject: Ternary op + autoboxing + null value = NPE?
  • From: Ramsey Gurley <email@hidden>
  • Date: Mon, 19 Oct 2009 11:31:55 -0400

Hi all,

I've just discovered that while

Double test = true?null:0d; //result: test is null

works without error, the following

Double test2 = true?(new Object(){public Double testMethod(){return null;}}.testMethod()):0d; //<-Throws NPE

Throws a NullPointerException. :-/  Ok, that sucks, so what about this?

Double test3 = new Object(){public Double testMethod2(){return null;}}.testMethod2(); // result: test3 is null
Double test4 = true?test3:0d; //<-Throws NPE


Also throws a NullPointerException. I suspect this has something to do with the autoboxing, because

Object test5 = true?new Object(){public Object testMethod3(){return null;}}.testMethod3():0d;

Works fine. I'm running OS X 10.5 and java 1.5 here at work. Is this a known issue? Or is this somehow expected behavior?

Ramsey


_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Ternary op + autoboxing + null value = NPE?
      • From: "Sobanski, Jedrzej" <email@hidden>
    • Re: Ternary op + autoboxing + null value = NPE?
      • From: Mike Schrag <email@hidden>
  • Prev by Date: mixed deployment of 4.5.1 + 5.x
  • Next by Date: Re: ERIndexing (was: How to achieve a fuzzy match searcher)
  • Previous by thread: Re: mixed deployment of 4.5.1 + 5.x
  • Next by thread: Re: Ternary op + autoboxing + null value = NPE?
  • Index(es):
    • Date
    • Thread