<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hey, it&#039;s OPOWER! &#187; Code</title>
	<atom:link href="http://www.heyitsopower.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.heyitsopower.com</link>
	<description>Energy Efficiency Starts at /usr/home</description>
	<lastBuildDate>Tue, 27 Jul 2010 20:14:37 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Boxed primitives and ==</title>
		<link>http://www.heyitsopower.com/culture/boxed-primitives-and/</link>
		<comments>http://www.heyitsopower.com/culture/boxed-primitives-and/#comments</comments>
		<pubDate>Thu, 27 May 2010 18:25:06 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Best Practice]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Culture]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=215</guid>
		<description><![CDATA[One part of programming culture at OPOWER is to program defensively, providing useful information when contracts are violated.   What does this have to do with boxed primitives?  Getting an assertion message of &#8220;Person 1001&#8217;s customer id 109032 didn&#8217;t match the passed-in customer&#8217;s id of 109032&#8243; seemed logically impossible, but was somehow true.
But [...]]]></description>
			<content:encoded><![CDATA[<p>One part of programming culture at OPOWER is to program defensively, providing useful information when contracts are violated.   What does this have to do with boxed primitives?  Getting an assertion message of &#8220;Person 1001&#8217;s customer id 109032 didn&#8217;t match the passed-in customer&#8217;s id of 109032&#8243; seemed logically impossible, but was somehow true.</p>
<p>But first, let&#8217;s talk about defensive coding and how we do it.  For example:</p>
<pre name="code" class="java">/**
 * frobs the bar and baz.
 * @param bar the bar to frob; may not be null
 * @param baz the baz to from; must be positive
 */
public String frob(String bar, int baz) {
  if (bar.length() &gt; baz) {
    return bar.substring(baz);
  }
  else {
    return bar;
  }
}</pre>
<p>If the contract is violated by the caller, we will get a <code>NullPointerException</code> or some other <code>StringIndexOutOfBoundsException</code>.  Not too helpful.  Instead, we use an internal validator helper class to provide useful messages.  This is <strong>crucial</strong> for properly understanding bugs that occur in production; there&#8217;s nothing worse than coming into work to find a <code>NullPointerException</code> in your inbox and no clue what went wrong.</p>
<pre name="code" class="java">/**
 * frobs the bar and baz.
 * @param bar the bar to frob; may not be null
 * @param baz the baz to from; must be positive
 */
public String frob(String bar, int baz) {
  Validate.notNull(bar,"bar must not be null to frob");
  Validate.isTrue(baz &gt; 0,"baz must be positive");
  if (bar.length() &gt; baz) {
    return bar.substring(baz);
  }
  else {
    return bar;
  }
}</pre>
<p><code>Validate.*</code>  methods essentially throw <code>IllegalArgumentException</code> if what they are checking for fails.<br />
We use this pattern extensively, even in constructors of simple data-structure style objects.  This (plus keeping this things immutable) allows users of these objects to safely rely upon the <code>get</code> methods behaving properly. I had need of a class to hold both a <code>Person</code> (representing a website user) and a <code>Customer</code> (representing a utility-company customer).  This class (called, naturally, <code>PersonAndCustomer</code>), takes both objects in its constructor and requires that they are both non-null.  As a further sanity check, I wanted to make sure that the <code>Person</code>&#8217;s <code>customerId</code> matched the id of the <code>Customer</code> that was being passed in (i.e. that they represented the same actual human in the real world):</p>
<pre name="code" class="java">public PersonAndCustomer(Person p, Customer c) {
  Validate.notNull(p,"Person may not be null");
  Validate.notNull(c,"Customer may not be null");
  Validate.isTrue(p.getCustomerId() == c.getId(),
    "Person %d's customer id %d didn't match passed-in customer's id %d",
    p.getId(),
    p.getCustomerId(),
    c.getId());
  ...
}</pre>
<p>Looks pretty inocuous, right?  Well, because these objects are Hibernate-managed, all of our ids are <code>Long</code> and not <code>long</code>.  So, my <code>isTrue</code> validation is really checking that the person&#8217;s <code>customerId</code> <em>object</em> is the <em>same object</em> as the customer&#8217;s <code>id</code> object.  What&#8217;s worse, in several months of development and production deployment, these two objects <em>happened to be the same</em>.</p>
<p>Until this week; we were testing our application for a new client and I got the error posted above (&#8220;Person 1001&#8217;s customer id 109032 didn&#8217;t match the passed-in customer&#8217;s id of 109032&#8243;).  It seems that much like how the JVM will re-use string objects, it also will sometimes re-use boxed objects as well.  But not always.  The fix for this is obvious, but I wanted to make sure I could actually recreate this situation.  So, I created a test that gave both the <code>Person</code> and <code>Customer</code> the same <em>value</em> for the customer id, but as different objects. and verified that the class could still be constructed.  Sure enough, the test failed.  The fix:</p>
<pre name="code" class="java">public PersonAndCustomer(Person p, Customer c) {
  Validate.notNull(p,"Person may not be null");
  Validate.notNull(c,"Customer may not be null");
  Validate.isTrue(p.getCustomerId().equals(c.getId()),
    "Person %d's customer id %d didn't match passed-in customer's id %d",
    p.getId(),
    p.getCustomerId(),
    c.getId());
  ...
}</pre>
<p>What&#8217;s interesting is that if one end of the <code>==</code> is a primitive, the JVM will unbox the other one and the test succeeds:</p>
<pre name="code" class="java">Long l1 = new Long(45L);
Long l2 = new Long(45L);

System.out.println(l1 == l2);      // false
System.out.println(l1.equals(l2)); // true
System.out.println(l1 == 45L);     // true!</pre>
<p>The moral of the story is to always know what you are comparing.  Might even be best to always use <code>.equals()</code> unless the compiler complains.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/culture/boxed-primitives-and/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dave&#8217;s Talk at ScalaDays 2010</title>
		<link>http://www.heyitsopower.com/code/daves-talk-at-scaladays-2010/</link>
		<comments>http://www.heyitsopower.com/code/daves-talk-at-scaladays-2010/#comments</comments>
		<pubDate>Mon, 03 May 2010 13:29:26 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=188</guid>
		<description><![CDATA[OPOWER graciously sent me to Switzerland this year for ScalaDays 2010.  I was lucky enough to be asked to present on &#8220;Sneaking Scala into the Enterprise&#8221;.  OPOWER sponsored the videography.  My talk, on starting to use Scala in your organization (based on my experience at OPOWER), is linked below; all the talks [...]]]></description>
			<content:encoded><![CDATA[<p>OPOWER graciously sent me to Switzerland this year for ScalaDays 2010.  I was lucky enough to be asked to present on &#8220;Sneaking Scala into the Enterprise&#8221;.  OPOWER sponsored the videography.  My talk, on starting to use Scala in your organization (based on my experience at OPOWER), is linked below; all the talks are online <a href="http://days2010.scala-lang.org/node/136">here</a>.<br />
<a href="http://days2010.scala-lang.org/node/138/169"><img class="alignnone size-full wp-image-189" title="Video | Scala Days 2010" src="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2010/04/Video-Scala-Days-2010.jpg" alt="Video | Scala Days 2010" width="648" height="388" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/code/daves-talk-at-scaladays-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alfresco 3.3 Lunch &amp; Learn</title>
		<link>http://www.heyitsopower.com/code/alfresco-3-3-lunch-learn/</link>
		<comments>http://www.heyitsopower.com/code/alfresco-3-3-lunch-learn/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 21:57:25 +0000</pubDate>
		<dc:creator>Tom Vaughan</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Alfresco]]></category>
		<category><![CDATA[Content Management]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=201</guid>
		<description><![CDATA[OPOWER attended the Reston, VA "Alfresco 3.3 lunch &#038; learn" seminar this week, hosted by the generous folks over at SiteWorx.  Alfresco 3.3 looks support the CMIS 1.0 spec and head further into the ECM space.]]></description>
			<content:encoded><![CDATA[<p>I attended the Reston, VA &#8220;Alfresco 3.3 lunch &amp; learn&#8221; seminar this week, hosted by the generous folks over at <a title="SiteWorx" href="http://www.siteworx.com/" target="_blank">SiteWorx</a>.  I have a couple years as &#8220;CMS guru&#8221; at some previous jobs so in addition to being interested in the field, I&#8217;m also the support guy in-house for our CMS needs.</p>
<p>We here at OPOWER use Alfresco Community 3.2 as a glorified &#8220;XML editing tool&#8221; that was easy to setup, configure and hand over to the business to allow them to contribute XML-based content that our applications can consume.  As a F/LOSS solution, it&#8217;s fit our needs pretty well and is generally a low-maintenance piece of our infrastructure.</p>
<p>I attribute my &#8220;low maintenance&#8221; characterization of an Alfresco installation mostly to the patience of my small user base, who are very accommodating to the quirks and limitations of the installed (and neglected) instance.</p>
<p>The 3.3 lunch and learn was intro&#8217;d by Chris from SiteWorx who surveyed the CMS landscape and equated the emerging CMIS spec as &#8220;content&#8217;s ODBC&#8221; which I thought to be a quite fitting analogy.</p>
<p>Richard Im from Alfresco then spoke for about 45 minutes about the new features Alfresco 3.3 contained:</p>
<p><strong>WCM Improvements</strong></p>
<ul>
<li>new web-based editor, reminiscent of Interwoven&#8217;s in-context editor from the 6.5/7.0 era</li>
<li>new bi-directional deployment capabilities (including addition of &#8220;delivery server&#8221; infrastructure possibilities like several other CMS offerings)</li>
<li>&#8220;Straight through&#8221; publishing without workflows</li>
<li>google-like search on metadata attributes</li>
</ul>
<p><strong>Share</strong></p>
<ul>
<li>Evolving share into more of a bit-for-bit replacement of the &#8220;traditional&#8221; UI (which Richard referred to as &#8220;DM&#8221;&#8230; &#8220;document manager?&#8221;)</li>
<li>Permission control a la DM</li>
<li>Rules and Actions just like in DM</li>
<li>Data Lists (like Share Point&#8217;s project lists)</li>
</ul>
<p>I asked the question: &#8220;what&#8217;s the medium-term road map for DM, if Alfresco seems intent on mirroring all(?) functionality in the traditional UI via the /share context?&#8221;  Richard wouldn&#8217;t definitively say that the traditional app is going to be deprecated any time soon, but it certainly appears that way&#8230;</p>
<p><strong>&#8220;Integration&#8221; improvements</strong></p>
<p>I think this suite of improvements is geared towards the enterprise crowd:</p>
<ul>
<li>Full CMIS 1.0 spec implemented as of 3.3 (the only open source implementation known to do so)</li>
<li>ACLs</li>
<li>Change Logs</li>
<li>Additional SOA/REST services and support</li>
<li>Ability to save off google docs in alfresco for management (!)</li>
</ul>
<p>My big take-aways from the lunch and Q&amp;A session was that Alfresco&#8217;s 3.3 feature list and 3.4 direction seem to put them on more of a competitive footing with monster ECM vendors like Interwoven.  It&#8217;s maybe an odd direction for an open source project to steer because while Alfresco certainly employs their own development team, I&#8217;m not sure how much community interest there is in contributing to some of the more mundane enterprise ECM concerns that need to be built or integrated.  On the other hand, Alfresco, Inc. does survive with enterprise support contracts that smaller shops like mine are unlikely to ever pay top-dollar for, so maybe it&#8217;s a long term survival strategy.</p>
<p>Long term, I&#8217;m interested in exploring architectures available to us with a SOA-enabled CMIS layer and eventually ditch the custom-DAO layer we&#8217;re running right now against Alfresco-exported XML flat files.  Even if that never happens, it&#8217;s exciting to see the kinds of complexity that open source projects are able to attack.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/code/alfresco-3-3-lunch-learn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When adding more threads makes it all slower</title>
		<link>http://www.heyitsopower.com/code/when-adding-more-threads-makes-it-all-slower/</link>
		<comments>http://www.heyitsopower.com/code/when-adding-more-threads-makes-it-all-slower/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 18:07:25 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[scaling]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=154</guid>
		<description><![CDATA[I&#8217;ve been working on a new feature that requires analysis of each individual&#8217;s entire energy-use history.  In other words, I have a process that will touch every single bit of data in our database. This should be a rare thing, so if it takes a while, it&#8217;s not that big of a deal.  [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a new feature that requires analysis of each individual&#8217;s entire energy-use history.  In other words, I have a process that will touch <strong>every single bit of data</strong> in our database. This should be a rare thing, so if it takes a while, it&#8217;s not that big of a deal.  My initial implementation was on track to complete in&#8230;11 days.</p>
<p>My first thought was: there&#8217;s lots of blocking reading and writing from the database, so adding some threads should speed things up.  While one thread was analyzing Bob&#8217;s energy data, another could be fetching Mary&#8217;s, while another could be updating Joe&#8217;s meta-data with the results.  Or so I thought.</p>
<p>The more threads I added, the slower the entire thing became.  It turned out that <strong>the fastest implementation was a single-threaded one</strong>.  But why?  It all has to do with the diminishing returns one gets from scaling out.</p>
<p>If you think of a task as having a serial component, which cannot be broken up concurrently, and then multiple tasks which <strong>can</strong> be done concurrently, we can analyze the returns we get by increasing the number of available processors (threads, in my case).  This is <a href="http://en.wikipedia.org/wiki/Amdahl%27s_law">Amdahl&#8217;s Law</a> and is exemplified by the following equation (where &#8220;x&#8221; is the number of processors or threads, and &#8220;s&#8221; is the percentage of your overall task that must be serialized; &#8220;y&#8221; is the increase in speed you will see from scaling).<br />
<img class="alignnone size-full wp-image-157" title="Amdahl's Equation" src="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2009/11/amdahl.png" alt="Amdahl's Equation" width="97" height="34" /></p>
<p>When you graph this, it&#8217;s pretty obvious that there are diminishing returns to adding more threads/processors (the graph below assumes that 90% of the overall job can be done concurrently).  As we add threads, we get less and less of a gain in speed.<br />
But there&#8217;s still a gain to get, so what happened to me?</p>
<p><img class="alignnone size-medium wp-image-165" title="Graph of Amdahl's Equation with 10% of our task serialized" src="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2009/11/Picture-3-300x106.png" alt="Graph of Amdahl's Equation with 10% of our task serialized" width="300" height="106" /></p>
<p>Amdahl&#8217;s law is actually pretty optimistic.  It doesn&#8217;t account for the overhead required to synchronize the shared data.  If we account for this, with a new value &#8220;k&#8221; ( the percentage penalty for maintaining consistency), we see that increasing our processors/threads actually starts to hurt us (this equation is in red)!</p>
<p><img class="alignnone size-medium wp-image-161" title="Taking shared state synchronization into account" src="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2009/11/Coherence-300x105.png" alt="Taking shared state synchronization into account" width="300" height="105" /></p>
<p>In my case, almost all of this synchronization is happening within the database; it turns out that almost all the time my process needs is accessing data from the database.  So, I dialed it down to only one thread, and we should be done early next week.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/code/when-adding-more-threads-makes-it-all-slower/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slides on Improving Your Agile Development Process</title>
		<link>http://www.heyitsopower.com/development/slides-on-improving-your-agile-development-process/</link>
		<comments>http://www.heyitsopower.com/development/slides-on-improving-your-agile-development-process/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 17:32:40 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Workflow]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[devdays]]></category>
		<category><![CDATA[process improvement]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=131</guid>
		<description><![CDATA[Dead last, after the headline act, and after Joel Spolsky told everyone to go home, I did a lightning talk at DC&#8217;s recent DevDays (A StackOverflow production) on how we have used process metrics from our bug tracker to improve our process.
Improving your Agile Process
View more documents from David Copeland.

]]></description>
			<content:encoded><![CDATA[<p>Dead last, after the headline act, and after Joel Spolsky told everyone to go home, I did a lightning talk at DC&#8217;s recent DevDays (<a href="http://www.stackoverflow.com">A StackOverflow</a> production) on how we have used <a href="/development/measuring-our-awesomeness-iteration-by-iteration/">process metrics</a> from our bug tracker to improve our process.</p>
<div id="__ss_2359457" style="width: 425px; text-align: left;"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" title="Improving your Agile Process" href="http://www.slideshare.net/davetron5000/measuring-agile-process-shorter-2359457">Improving your Agile Process</a><object style="margin:0px" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=measuringagileprocess-shorter-091027130310-phpapp01&amp;rel=0&amp;stripped_title=measuring-agile-process-shorter-2359457" /><param name="allowfullscreen" value="true" /><embed style="margin:0px" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=measuringagileprocess-shorter-091027130310-phpapp01&amp;rel=0&amp;stripped_title=measuring-agile-process-shorter-2359457" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">documents</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/davetron5000">David Copeland</a>.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/development/slides-on-improving-your-agile-development-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When is a null not a null?</title>
		<link>http://www.heyitsopower.com/code/when-is-a-null-not-a-null/</link>
		<comments>http://www.heyitsopower.com/code/when-is-a-null-not-a-null/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 14:48:15 +0000</pubDate>
		<dc:creator>Tom Vaughan</dc:creator>
				<category><![CDATA[Best Practice]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=74</guid>
		<description><![CDATA[tl/dr: <em>Don't have a non-null object's .toString() display "null". It's confusing and not helpful when looking at object states in IDE debuggers.</em>

I recently converted the attribute of our Person POJO that stored a user's email address from a java.lang.String to a javax.mail.InternetAddress.  Call it not enough testing or lack of imagination, but I introduced a Null Pointer Exception in a back-office web flow where a new user is created for our customer service application.  When a new CSR account is created and the email address is left blank, an NPE gets thrown up.  Embarrassing, but easy to fix, right?]]></description>
			<content:encoded><![CDATA[<p>tl/dr: <em>Don&#8217;t have a non-null object&#8217;s .toString() display &#8220;null&#8221;. It&#8217;s confusing and not helpful when looking at object states in IDE debuggers.</em></p>
<p>I recently converted the attribute of our Person POJO that stored a user&#8217;s email address from a java.lang.String to a javax.mail.InternetAddress.  Call it not enough testing or lack of imagination, but I introduced a Null Pointer Exception in a back-office web flow where a new user is created for our customer service application.  When a new CSR account is created and the email address is left blank, an NPE gets thrown up.  Embarrassing, but easy to fix, right?</p>
<p>Just looking at the stack trace narrows it down immediately:</p>
<pre class="java">2009-09-09 16:56:53,636 WARN  [btpool0-1] [REPORT] [WARN] Handler execution resulted in exception
java.lang.NullPointerException
	at javax.mail.internet.InternetAddress.parse(InternetAddress.java:609)
	at javax.mail.internet.InternetAddress.parse(InternetAddress.java:569)
	at javax.mail.internet.InternetAddress.(InternetAddress.java:105)
	at poscore.db.InternetAddressUserType.deepCopy(InternetAddressUserType.java:93)
	at org.hibernate.type.CustomType.deepCopy(CustomType.java:179)
	at org.hibernate.type.TypeFactory.deepCopy(TypeFactory.java:374)</pre>
<p>Ahh&#8230;yeah&#8230;that custom hibernate type I wrote to translate VARCHARs to InternetAddresses and vice versa.  Ok, what does that deep copy method look like?</p>
<pre class="java">    public Object deepCopy(Object value) throws HibernateException {
        if(value == null) {
            return null;
        }
        InternetAddress original = (InternetAddress)value;
        InternetAddress copy = null;
        try {
            copy = new InternetAddress(original.getAddress());
        }
        catch (AddressException ex) {
            throw new HibernateException("Unable to deep copy email address '" + original.getAddress() + "'");
        }
        return copy;
    }</pre>
<p>It turns out, the error is right here:</p>
<pre class="java">            copy = new InternetAddress(original.getAddress());</pre>
<p>You can&#8217;t pass a null to the InternetAddress constructor.  It was late in the day and I must not have internalized that there&#8217;s no way <em>value </em>or <em>original</em> could be null, because my first instinct was that the NPE was actually the result of calling &#8220;.getAddress()&#8221; on a null <em>original</em> object&#8230;.not that the constructor can&#8217;t take a null.</p>
<p>While I was on that assumption (that it was the <em>original</em> object that was null), I fired up my debugger and got confused by what appeared to be null-checks failing to check nulls. Check out this screen shot of the NPE about to be thrown after what appears to be 2 null checks failing to prevent the NPE:<br />
<img class="aligncenter size-full wp-image-77" title="null_internet_address" src="http://www.heyitsopower.com/wordpress/wp-content/uploads/2009/09/null_internet_address.png" alt="null_internet_address" width="705" height="606" /></p>
<p>The arrows marked (A) and (B) shows what appear to be null objects passing null checks (in the top pane) even though they&#8217;re being reported as null (in the bottom pane).  The green line (C) shows the code falling through to that line just before it throws up the NPE.</p>
<p>Of course, <em>value</em> and <em>original</em> aren&#8217;t null at all&#8230;it&#8217;s just that their .toString() methods report them to be null.  Here&#8217;s the InternetAddress.toString method:</p>
<pre class="java">  276       public String toString() {
  277   	if (encodedPersonal == null &amp;&amp; personal != null)
  278   	    try {
  279   		encodedPersonal = MimeUtility.encodeWord(personal);
  280   	    } catch (UnsupportedEncodingException ex) { }
  281
  282   	if (encodedPersonal != null)
  283   	    return quotePhrase(encodedPersonal) + " &lt;" + address + "&gt;";
  284   	else if (isGroup() || isSimple())
  285   	    return address;
  286   	else
  287   	    return "&lt;" + address + "&gt;";
  288       }</pre>
<p>In my situation, I fell in to the &#8220;else if(isGroup() || isSimple())&#8221; case, which returns <em>address</em>, which is null, so the .toString() for the whole InternetAddress object is &#8220;null.&#8221;</p>
<p>I think the toString() method could benefit from another null-check right at line 284, which would mean an InternetAddress object with a null internal <em>address</em> String would display as &#8220;&lt;null&gt;&#8221;&#8230;that&#8217;s a more immediate clue that the object itself isn&#8217;t null.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/code/when-is-a-null-not-a-null/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Developer Law</title>
		<link>http://www.heyitsopower.com/development/new-developer-law/</link>
		<comments>http://www.heyitsopower.com/development/new-developer-law/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 14:06:25 +0000</pubDate>
		<dc:creator>Tom Vaughan</dc:creator>
				<category><![CDATA[Best Practice]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=34</guid>
		<description><![CDATA[NEW LAW FOR DEVELOPERS:

If you throw an exception about some connection being refused, you'd better damn well put what connection you were attempting to make in the exception message.

What inspired this law?  Thanks for asking.]]></description>
			<content:encoded><![CDATA[<p>NEW LAW FOR DEVELOPERS:</p>
<p><em>If you throw an exception about some connection being refused, you&#8217;d better damn well put what connection you were attempting to make in the exception message.</em></p>
<p>What inspired this law?  Thanks for asking.</p>
<p>Check out this snippet in the middle of an 80 line stack dump:</p>
<pre>2009-08-25 17:23:42.373::WARN:  Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'coreAutopatcher' defined in class path resource [config/migrationContext.xml]: Invocation of init method failed; nested exception is com.tacitknowledge.util.migration.MigrationException: Error applying patches:
com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)</pre>
<p>&#8220;A ResourcePool could not acquire a resource from its primary factory or source&#8221;.  Awesome.  Sooo helpful.  /wristsemoragegrowl</p>
<p>Also, a WARN?  Seriously?  You&#8217;re a connection pool.  Do you think not connecting to your underlying datasource warrants maybe something as stern as an ERROR?  Or, heaven forbid, a FATAL?</p>
<p>I&#8217;m sure I could have turned up logging somewhere, but I noticed Spring&#8217;s DelegatingDataSource bean standing out from among the stack lines and set a break point on its called method to figure out exactly which of my many connections was unable to be resolved:</p>
<p><img class="aligncenter size-full wp-image-37" title="what_am_i_connecting_to" src="http://www.heyitsopower.com/wordpress/wp-content/uploads/2009/08/what_am_i_connecting_to.png" alt="what_am_i_connecting_to" width="909" height="307" /></p>
<p>There&#8217;s the culprit!  localhost:5455.  You know, whoever the idiot is who runs that localhost server needs to get his act together.  I should call the guys from YouTube and have them do a Maury Povich-style video expose on why he can&#8217;t keep any of his connections stable.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/development/new-developer-law/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subversion Branching &#8220;Good&#8221; Practice</title>
		<link>http://www.heyitsopower.com/development/subversion-branching-good-practice/</link>
		<comments>http://www.heyitsopower.com/development/subversion-branching-good-practice/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 00:56:52 +0000</pubDate>
		<dc:creator>Jeff Kolesky</dc:creator>
				<category><![CDATA[Best Practice]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[branching]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=18</guid>
		<description><![CDATA[I am relatively new to Subversion — well, two years into using it now, but this is the first project I have used it on.  Subversion, like any tool, has its quirks and works best when you really know how to use it.  When I started, I treated the "trunk/branches/tags" directory structure exactly like a directory structure.  It took me a little playing around until I stumbled on what I would call a best practice.  When I checkout a new project, I do it like so:

svn co http://domain.com/svnroot/project/trunk project

That way, when I go to the project directory, I do not have to then go into the trunk directory to get to my files.]]></description>
			<content:encoded><![CDATA[<p>I am relatively new to Subversion — well, two years into using it now, but this is the first project I have used it on.  Subversion, like any tool, has its quirks and works best when you really know how to use it.  When I started, I treated the &#8220;trunk/branches/tags&#8221; directory structure exactly like a directory structure.  It took me a little playing around until I stumbled on what I would call a best practice.  When I checkout a new project, I do it like so:</p>
<p><code>svn co http://domain.com/svnroot/project/trunk project</code></p>
<p>That way, when I go to the <code>project</code> directory, I do not have to then go into the <code>trunk</code> directory to get to my files.  Saving an extra directory level is not the best benefit though.  When I set up my IDE (yes, I use an IDE), I put the IDE files in that one directory and do not have to recreate them for each branch or tag that I might check out.  I essentially treat the &#8220;trunk/branches/tags&#8221; part of the directory as pure metadata, which makes perfect sense to me.</p>
<p>When I switched over to this system, there was one big drawback.  I could not easily tell where I am just by looking at my prompt.  I had to run <code>svn info | grep URL</code> to see if I was on a branch.  So instead of letting my prompt handicap me, I decided to get smart about my prompt.  Using bash, my prompt used to look like this:</p>
<p><code>jeff:/opt/pose/main/report/src/main/java</code></p>
<p>but now it looks like this (supercharged with Subversion metadata):</p>
<p><code>jeff:/opt/pose/main/report/src/main/java [SVN: /main/report/trunk]</code></p>
<p>I&#8217;m no bash expert, so I dug around on the web and learned a bit about how <code>PROMPT_COMMAND</code> works.  Here is what I have in my <code>.bash_profile</code> now:</p>
<p><code><br />
function spwd ()<br />
{<br />
    stat .svn > /dev/null 2>&#038;1;<br />
    if [ "$?" == "0" ]; then<br />
        SURL=`svn info | grep URL | perl -pe 's/URL: (.*)/\1/'`;<br />
        if [ `echo ${SURL} | grep -E "branches|tags"` ]; then<br />
            SVER=`echo ${SURL} | perl -pe 's{.*/(branches|tags)/(.*)}{\1/\2}' | cut -d/ -f1-2`;<br />
            SPTH=`echo ${SURL} | perl -pe 's{.*svnroot/(.*)/(branches|tags)/.*}{/\1}'`;<br />
            SPWD="${SPTH}/${SVER}";<br />
        else<br />
            SPWD=`echo ${SURL} | perl -pe 's{.*svnroot/(.*)/trunk(.*)}{/\1/trunk}'`;<br />
        fi;<br />
        export PS1="\u:\w [SVN: $SPWD]\n$ ";<br />
    else<br />
        export PS1="\u:\w $ ";<br />
    fi<br />
}<br />
export PROMPT_COMMAND=spwd<br />
</code></p>
<p>It may not be the most efficient way to do it, but it sure works well and lets me know in an instant what trunk, branch or tag I happen to be working on at that very moment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/development/subversion-branching-good-practice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Measuring our awesomeness iteration by iteration</title>
		<link>http://www.heyitsopower.com/development/measuring-our-awesomeness-iteration-by-iteration/</link>
		<comments>http://www.heyitsopower.com/development/measuring-our-awesomeness-iteration-by-iteration/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 15:00:47 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[process improvment]]></category>
		<category><![CDATA[qa]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sinatra]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=4</guid>
		<description><![CDATA[<p>
Like a lot of startups (and big companies!) we use iterative development: we break up our work into "stories" describing features and implement as many as we can in one month.  We then repeat that until we conquer the world.  But, if we can do more, or work more efficiently with each iteration, our goal of world domination will approach that much quicker :)
</p>
<p>
The easiest way to do that is to look at the bugs our QA staff find in the product updates.  Although we have a lot of automated tests, we still need some eyes on the applications to check for things like text overruns of our printed reports, or JavaScript weirdness in some <a href="http://blog.digg.com/?p=878">less-than-well-behaved</a>) browsers.
</p>]]></description>
			<content:encoded><![CDATA[<p>
Like a lot of startups (and big companies!) we use iterative development: we break up our work into &#8220;stories&#8221; describing features and implement as many as we can in one month.  We then repeat that until we conquer the world.  But, if we can do more, or work more efficiently with each iteration, our goal of world domination will approach that much quicker <img src='http://www.heyitsopower.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</p>
<p>
The easiest way to do that is to look at the bugs our QA staff find in the product updates.  Although we have a lot of automated tests, we still need some eyes on the applications to check for things like text overruns of our printed reports, or JavaScript weirdness in some <a href="http://blog.digg.com/?p=878">less-than-well-behaved</a>) browsers.
</p>
<p>
After a few iterations, Anh (our beloved program manager) ran some queries on our bug-tracking database and, using some Excel magic, showed us numbers like &#8220;number of defects in the web application&#8221; and &#8220;average number of days a critical bug sat unassigned&#8221;.  This is good stuff; seeing hard data about what we&#8217;re doing lets us focus on inefficiency.  Since we release software every month (and launch new clients almost as frequently), this is a <b>huge</b> help in making each iteration better than the previous.
</p>
<p>
While Anh&#8217;s hand-jammed report was awesome, manually connecting SQLite and Excel is no fun for anyone.  I whipped up a basic Ruby application using <a href="http://www.sinatrarb.com/">Sinatra</a> to automate most of what we&#8217;d like to see.  We can now see how long critical defects site open and unfixed, as well as how many overall defects we&#8217;re fixing and even the <i>root source</i> of our defects (e.g. did we get the wrong requirements, or just mess up implementing them?)
</p>
<p>
We still need to show trends, however.  &#8220;Classic&#8221; thinking in software process improvement says to do that by dividing everything by lines of code; if we had 10 defects per 1,000 lines of code this month, but only 8 the following, we&#8217;re doing better.  This is not a great measure for us, since we are changing and enhancing our product (as opposed to writing fresh code each time), so we decided to normalize our measurements by the story points we assigned to the iteration.  This way, we can see charts like the one below (which says we are doing better each time):
</p>
<p><img src="http://www.heyitsopower.com/wordpress/wp-content/uploads/2009/08/MetricsChart.png" alt="Metrics Chart" title="Metrics Chart" width="442" height="314" class="alignnone size-full wp-image-7" /></p>
<p>
This information is dead simple to collect; the burden on developers and testers when writing defects is almost nothing.  With only a priority, severity, and &#8220;source of defect&#8221;, we can collect a lot of advanced information about our development process &mdash; and make it better iteration by iteration.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.heyitsopower.com/development/measuring-our-awesomeness-iteration-by-iteration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
