<?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>Tue, 22 Nov 2011 10:53:40 +0200</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Maniganda Prakash</title>
		<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/comment-page-1/#comment-13866</link>
		<dc:creator>Maniganda Prakash</dc:creator>
		<pubDate>Wed, 29 Dec 2010 13:31:59 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=279#comment-13866</guid>
		<description>&lt;p&gt;It must be &quot;if(!result.isEmpty())&quot; instead of &quot;if(result.isEmpty())&quot; (Andre had already pointed it out)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>It must be &#8220;if(!result.isEmpty())&#8221; instead of &#8220;if(result.isEmpty())&#8221; (Andre had already pointed it out)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Act Like a Senior Developer &#124; Test Server</title>
		<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/comment-page-1/#comment-8530</link>
		<dc:creator>Act Like a Senior Developer &#124; Test Server</dc:creator>
		<pubDate>Sat, 12 Jun 2010 03:05:00 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=279#comment-8530</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: Isa Goksu</title>
		<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/comment-page-1/#comment-7273</link>
		<dc:creator>Isa Goksu</dc:creator>
		<pubDate>Sat, 10 Apr 2010 17:54:31 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=279#comment-7273</guid>
		<description>&lt;p&gt;In that case, I&#039;d recommend using NullObjectPattern. You&#039;d have User domain model. You extend this model with UnknownUser. An in any case of exception you can easily return new UnknownUser which doesn&#039;t have any property set. You workflow would continue without any problem. You don&#039;t have to check anything. Then again if you would like to have a business logic around users that are not in DB, then u can check this by &quot;if user instanceof UnknownUser&quot; kinda statement and put your business logic there.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>In that case, I&#8217;d recommend using NullObjectPattern. You&#8217;d have User domain model. You extend this model with UnknownUser. An in any case of exception you can easily return new UnknownUser which doesn&#8217;t have any property set. You workflow would continue without any problem. You don&#8217;t have to check anything. Then again if you would like to have a business logic around users that are not in DB, then u can check this by &#8220;if user instanceof UnknownUser&#8221; kinda statement and put your business logic there.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Sunil</title>
		<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/comment-page-1/#comment-7266</link>
		<dc:creator>Sunil</dc:creator>
		<pubDate>Sat, 10 Apr 2010 13:21:54 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=279#comment-7266</guid>
		<description>&lt;p&gt;Thanks a lot.This is really useful.One question though&lt;/p&gt;

&lt;p&gt;&quot;throw UserNotFoundException(&quot;No user found with guid: %1$s&quot;, guid); // or any ServiceException you like..&quot;&lt;/p&gt;

&lt;p&gt;If I want to continue after this exception is thrown wouldn&#039;t I need to handle with an if and else loop?
What do you think will be a better approach to handle such cases?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks a lot.This is really useful.One question though</p>

<p>&#8220;throw UserNotFoundException(&#8221;No user found with guid: %1$s&#8221;, guid); // or any ServiceException you like..&#8221;</p>

<p>If I want to continue after this exception is thrown wouldn&#8217;t I need to handle with an if and else loop?
What do you think will be a better approach to handle such cases?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Lexandro weblogja &#187; NPE</title>
		<link>http://isagoksu.com/2009/development/java/how-to-avoid-nullpointerexceptions-npe/comment-page-1/#comment-6817</link>
		<dc:creator>Lexandro weblogja &#187; NPE</dc:creator>
		<pubDate>Mon, 15 Mar 2010 23:27:32 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=279#comment-6817</guid>
		<description>&lt;p&gt;[...] olvasgattam egy érdekes cikket a null pointer exception elkerüléséről,  ahol a srác felvázolt pár elképzelést [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] olvasgattam egy érdekes cikket a null pointer exception elkerüléséről,  ahol a srác felvázolt pár elképzelést [...]</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-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>
</channel>
</rss>

