<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to Avoid NullPointerExceptions (NPE)?</title>
	<atom:link href="http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/feed/" rel="self" type="application/rss+xml" />
	<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/</link>
	<description>Nobody can be perfect, but you can think better, design better, and always use baby steps!</description>
	<lastBuildDate>Thu, 11 Mar 2010 08:07:26 +0200</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Isa Goksu</title>
		<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/comment-page-1/#comment-4613</link>
		<dc:creator>Isa Goksu</dc:creator>
		<pubDate>Fri, 27 Nov 2009 18:03:11 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=279#comment-4613</guid>
		<description>&lt;p&gt;@cease, in that case I&#039;d not prefer both, the best would be NullUser :) However early UserNotFound exception is still more meaningful than trying to figure out how come it became null later in the code.&lt;/p&gt;

&lt;p&gt;@andre 10x for correcting&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@cease, in that case I&#8217;d not prefer both, the best would be NullUser :) However early UserNotFound exception is still more meaningful than trying to figure out how come it became null later in the code.</p>

<p>@andre 10x for correcting</p>]]></content:encoded>
	</item>
	<item>
		<title>By: André</title>
		<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/comment-page-1/#comment-4611</link>
		<dc:creator>André</dc:creator>
		<pubDate>Fri, 27 Nov 2009 13:54:40 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=279#comment-4611</guid>
		<description>&lt;p&gt;I guess it should be &quot;if (!result.isEmpty())&quot; instead of &quot;if (result.isEmpty())&quot; in your examples.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I guess it should be &#8220;if (!result.isEmpty())&#8221; instead of &#8220;if (result.isEmpty())&#8221; in your examples.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Act Like a Senior Developer &#8211; About Clean Code</title>
		<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/comment-page-1/#comment-4558</link>
		<dc:creator>Act Like a Senior Developer &#8211; About Clean Code</dc:creator>
		<pubDate>Wed, 25 Nov 2009 19:03:48 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=279#comment-4558</guid>
		<description>&lt;p&gt;[...] more information on this topic, please read my other post about null pointer [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] more information on this topic, please read my other post about null pointer [...]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: cease</title>
		<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/comment-page-1/#comment-4557</link>
		<dc:creator>cease</dc:creator>
		<pubDate>Wed, 25 Nov 2009 18:55:55 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=279#comment-4557</guid>
		<description>&lt;p&gt;what about the case you&#039;re querying for an object of type User (for example) and it doesn&#039;t exist, do you throw exception or return null... I would prefer the null check than a checked exception, returning new User makes no sense in this case.  thoughts ?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>what about the case you&#8217;re querying for an object of type User (for example) and it doesn&#8217;t exist, do you throw exception or return null&#8230; I would prefer the null check than a checked exception, returning new User makes no sense in this case.  thoughts ?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Isa Goksu</title>
		<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/comment-page-1/#comment-2025</link>
		<dc:creator>Isa Goksu</dc:creator>
		<pubDate>Tue, 12 May 2009 17:30:36 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=279#comment-2025</guid>
		<description>&lt;p&gt;@mike If you have a situation that your service users might add elements to the returning collection (as in API/framework development, or any open source library development), then I&#039;d definitely say &quot;Yes, you should return an empty array list&quot;. Then again, generally Service/DAO clients don&#039;t add anything new to the returning collection as far as I concern. To me if you&#039;re adding a new element to the result set by yourself, there is something smelling in that code, instead they might try using double brace initialization to do their custom stuff. And even though they might get UnsupportedOperationException, I think it&#039;s still meaningful than NPE :) At least this time you know where exactly the problem is, right ;)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@mike If you have a situation that your service users might add elements to the returning collection (as in API/framework development, or any open source library development), then I&#8217;d definitely say &#8220;Yes, you should return an empty array list&#8221;. Then again, generally Service/DAO clients don&#8217;t add anything new to the returning collection as far as I concern. To me if you&#8217;re adding a new element to the result set by yourself, there is something smelling in that code, instead they might try using double brace initialization to do their custom stuff. And even though they might get UnsupportedOperationException, I think it&#8217;s still meaningful than NPE :) At least this time you know where exactly the problem is, right ;)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/comment-page-1/#comment-2024</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Tue, 12 May 2009 14:47:19 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=279#comment-2024</guid>
		<description>&lt;p&gt;My problem is with return Collections.EMPTY_LIST.&lt;/p&gt;

&lt;p&gt;In my opinion, you are trading a NullPointerException for an UnsupportedOperationException because Collections.EMPTY_LIST is immutable. If any code tries to add elements to the returned collection, they are in for an exception. I suppose I would have just return new ArrayList();&lt;/p&gt;

&lt;p&gt;Thoughts?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>My problem is with return Collections.EMPTY_LIST.</p>

<p>In my opinion, you are trading a NullPointerException for an UnsupportedOperationException because Collections.EMPTY_LIST is immutable. If any code tries to add elements to the returned collection, they are in for an exception. I suppose I would have just return new ArrayList();</p>

<p>Thoughts?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: selman tayyar</title>
		<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/comment-page-1/#comment-2017</link>
		<dc:creator>selman tayyar</dc:creator>
		<pubDate>Mon, 11 May 2009 19:55:28 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=279#comment-2017</guid>
		<description>&lt;p&gt;Nice post.This is the first time i&#039;ve heard about npe annotation of intellij. it sounds worth trying!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Nice post.This is the first time i&#8217;ve heard about npe annotation of intellij. it sounds worth trying!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Isa Goksu</title>
		<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/comment-page-1/#comment-1994</link>
		<dc:creator>Isa Goksu</dc:creator>
		<pubDate>Sat, 09 May 2009 21:01:03 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=279#comment-1994</guid>
		<description>&lt;p&gt;@esat, yeah there might be some performance issues depending on the data structure (I guess mostly ArrayList, for Maps and Sets hashing mechanism in charge), but it&#039;s totally up to the developer how to design the software. As I mentioned in the article, I don&#039;t think all these practices can be applicable for all kind of situations. &lt;/p&gt;

&lt;p&gt;@pavel, I think the purpose of the factory and builder patterns are to build/create a proper instance of an object. If it&#039;s not building/creating a proper instance, then it&#039;s not a well-applied factory pattern. I don&#039;t think it would return null. Then again, all these methods are to avoid NPE, not to remove completely from your code base ;)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@esat, yeah there might be some performance issues depending on the data structure (I guess mostly ArrayList, for Maps and Sets hashing mechanism in charge), but it&#8217;s totally up to the developer how to design the software. As I mentioned in the article, I don&#8217;t think all these practices can be applicable for all kind of situations. </p>

<p>@pavel, I think the purpose of the factory and builder patterns are to build/create a proper instance of an object. If it&#8217;s not building/creating a proper instance, then it&#8217;s not a well-applied factory pattern. I don&#8217;t think it would return null. Then again, all these methods are to avoid NPE, not to remove completely from your code base ;)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: shailendra</title>
		<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/comment-page-1/#comment-1989</link>
		<dc:creator>shailendra</dc:creator>
		<pubDate>Sat, 09 May 2009 03:28:47 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=279#comment-1989</guid>
		<description>&lt;p&gt;Excellent post!! Keep posting&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Excellent post!! Keep posting</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Pavel</title>
		<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/comment-page-1/#comment-1970</link>
		<dc:creator>Pavel</dc:creator>
		<pubDate>Thu, 07 May 2009 23:41:16 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=279#comment-1970</guid>
		<description>&lt;p&gt;With regards to the Factory pattern as approach to avoid NPE, do you consider all Creational Patterns as useful instruments for this purpose? There is still possibility that Factory returns null, right?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>With regards to the Factory pattern as approach to avoid NPE, do you consider all Creational Patterns as useful instruments for this purpose? There is still possibility that Factory returns null, right?</p>]]></content:encoded>
	</item>
</channel>
</rss>
