Preferred way of checking nulls for defensive copies
<p>Suppose I have the following method:</p>

<pre><code>public void change(Map&lt;String, String&gt; map)
</code></pre>

<p>I would like to throw an exception if <code>map</code> is <code>null</code> and make a defensive copy if it's not.</p>

<p>Would this be preferred:</p>

<pre><code>public void change(Map&lt;String, String&gt; map)
{
    Map&lt;String, String&gt; temp = null;

    synchronized (map) {
            if (map == null)
                throw new NullPointerException("map is null");
        temp = new HashMap&lt;String, Object&gt;(map);
}
</code></pre>

<p>or</p>

<pre><code>public void change(Map&lt;String, String&gt; map)
    try 
    {
        Map&lt;String, String&gt; temp = new HashMap&lt;String, Object&gt;(map);
    } 
    catch (NullPointerException e) 
    {
        throw new NullPointerException("map is null");
    }
</code></pre>

<p>or is there a better way? why and why not.</p>

<p>EDITS: revised a few typos I had:</p>

<p>"properties" should be "map"</p>

<p>(String, Object) should be "(String, String)"</p>

<p>Thanks!</p>
