<?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: throw null</title>
	<atom:link href="http://tech.puredanger.com/index.php/2008/06/23/throw-null/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.puredanger.com/2008/06/23/throw-null/</link>
	<description>Alex Miller&#039;s technical blog</description>
	<lastBuildDate>Wed, 28 Jul 2010 22:41:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Neal Gafter</title>
		<link>http://tech.puredanger.com/2008/06/23/throw-null/comment-page-1/#comment-60056</link>
		<dc:creator>Neal Gafter</dc:creator>
		<pubDate>Sat, 28 Jun 2008 21:12:05 +0000</pubDate>
		<guid isPermaLink="false">http://tech.puredanger.com/2008/06/23/throw-null/#comment-60056</guid>
		<description>Although null is assignable to every reference type, the type of null is not itself a reference type. It was our intent that the requirement that the expression in a throw statement be a reference type was to be removed from the third edition of the JLS, but that change never actually made it into the published version. Thus, this is a javac compiler bug which I introduced in SE 5.</description>
		<content:encoded><![CDATA[<p>Although null is assignable to every reference type, the type of null is not itself a reference type. It was our intent that the requirement that the expression in a throw statement be a reference type was to be removed from the third edition of the JLS, but that change never actually made it into the published version. Thus, this is a javac compiler bug which I introduced in SE 5.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Burke</title>
		<link>http://tech.puredanger.com/2008/06/23/throw-null/comment-page-1/#comment-59011</link>
		<dc:creator>Eric Burke</dc:creator>
		<pubDate>Wed, 25 Jun 2008 11:47:03 +0000</pubDate>
		<guid isPermaLink="false">http://tech.puredanger.com/2008/06/23/throw-null/#comment-59011</guid>
		<description>The comments are funny...arguing about whether to throw NPE or IAE is silly, because *both* are acceptable. The fact is, the documentation for these exceptions leaves much open to interpretation. It is perfectly valid to argue that a null parameter is an illegal argument, and that completely agrees with the JavaDoc comments for IAE. You can also find examples and documentation that suggest NPE is appropriate. This is a classic code style argument all over again. Trust me folks, the most important thing is to fail fast, it really doesn&#039;t matter if you choose IAE or NPE. Either way, your program will abort and which of these two exceptions you choose won&#039;t make it any harder to diagnose the problem.</description>
		<content:encoded><![CDATA[<p>The comments are funny&#8230;arguing about whether to throw NPE or IAE is silly, because *both* are acceptable. The fact is, the documentation for these exceptions leaves much open to interpretation. It is perfectly valid to argue that a null parameter is an illegal argument, and that completely agrees with the JavaDoc comments for IAE. You can also find examples and documentation that suggest NPE is appropriate. This is a classic code style argument all over again. Trust me folks, the most important thing is to fail fast, it really doesn&#8217;t matter if you choose IAE or NPE. Either way, your program will abort and which of these two exceptions you choose won&#8217;t make it any harder to diagnose the problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reinier Zwitserloot</title>
		<link>http://tech.puredanger.com/2008/06/23/throw-null/comment-page-1/#comment-58703</link>
		<dc:creator>Reinier Zwitserloot</dc:creator>
		<pubDate>Tue, 24 Jun 2008 12:02:16 +0000</pubDate>
		<guid isPermaLink="false">http://tech.puredanger.com/2008/06/23/throw-null/#comment-58703</guid>
		<description>@Eugene: You manually throw an NPE so that the NPE happends in the right place. Lets say I have a constructor with 1 parameter, &quot;String foo&quot;, and part of the contract is that foo isn&#039;t null. But in the constructor, I just store foo, I don&#039;t do anything with it - but in almost any other method, I dereference foo.

I could just write &#039;this.foo = foo&#039; in my constructor and be safe in the knowledge that almost any further usage of my object will result in NPEs automatically, but this is bad coding. The &#039;bug&#039; is setting foo to null in the first place, THATS where your debugging efforts should start (when I call new Doohickey(bar), where bar is null, that&#039;s the bug, not when I later call doohickey.xyzzy() - the NPE stack trace of that event is useless).</description>
		<content:encoded><![CDATA[<p>@Eugene: You manually throw an NPE so that the NPE happends in the right place. Lets say I have a constructor with 1 parameter, &#8220;String foo&#8221;, and part of the contract is that foo isn&#8217;t null. But in the constructor, I just store foo, I don&#8217;t do anything with it &#8211; but in almost any other method, I dereference foo.</p>
<p>I could just write &#8216;this.foo = foo&#8217; in my constructor and be safe in the knowledge that almost any further usage of my object will result in NPEs automatically, but this is bad coding. The &#8216;bug&#8217; is setting foo to null in the first place, THATS where your debugging efforts should start (when I call new Doohickey(bar), where bar is null, that&#8217;s the bug, not when I later call doohickey.xyzzy() &#8211; the NPE stack trace of that event is useless).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: contrapunctus</title>
		<link>http://tech.puredanger.com/2008/06/23/throw-null/comment-page-1/#comment-58679</link>
		<dc:creator>contrapunctus</dc:creator>
		<pubDate>Tue, 24 Jun 2008 10:22:22 +0000</pubDate>
		<guid isPermaLink="false">http://tech.puredanger.com/2008/06/23/throw-null/#comment-58679</guid>
		<description>it compiles because null can simply cast into System.Exception:)</description>
		<content:encoded><![CDATA[<p>it compiles because null can simply cast into System.Exception:)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luigi R. Viggiano</title>
		<link>http://tech.puredanger.com/2008/06/23/throw-null/comment-page-1/#comment-58668</link>
		<dc:creator>Luigi R. Viggiano</dc:creator>
		<pubDate>Tue, 24 Jun 2008 09:22:55 +0000</pubDate>
		<guid isPermaLink="false">http://tech.puredanger.com/2008/06/23/throw-null/#comment-58668</guid>
		<description>In my opinion the NullpointerException could be thrown when the JVM tries to call methods on the null reference, as it was a real Throwable instance. Possibly at the fillInStackTrace() method.

This produces the same output (and explains what I think happens):

public class Weird {  

    public static void main(String[] args) {  
         ((Throwable)null).fillInStackTrace();
    }  

}</description>
		<content:encoded><![CDATA[<p>In my opinion the NullpointerException could be thrown when the JVM tries to call methods on the null reference, as it was a real Throwable instance. Possibly at the fillInStackTrace() method.</p>
<p>This produces the same output (and explains what I think happens):</p>
<p>public class Weird {  </p>
<p>    public static void main(String[] args) {<br />
         ((Throwable)null).fillInStackTrace();<br />
    }  </p>
<p>}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.496 seconds -->
