How to create deep copy of array passed, if the array is valid?
<p>SO an IPv4 array is passed to this method, and if valid, creates a deep copy of the array in the instance variable "parts"</p>

<pre><code>/**
 * If the ip address from the array passed (data) is valid,
 * makes a deep copy of the array passed in the instance variable parts.
 * For example, if data = {192,168,0,1}, parts should become {192,168,0,1}
 * by copying each item of data into corresponding item in parts.
 * If the ip address passed is invalid (for example {500,4,60,216}
 * or {192,16,01}, or {13,13,13,13,13}, parts should become {0,0,0,0}
 * 
 * remember to reset the instance array parts before you do anything else
 * @param data
 */
public void setParts(int[] data) {
this.parts = new int[4];
if (data.length != 4){
    parts = new int[]{0,0,0,0};
}
else
    for (int i = 0; i &lt;= data.length; i++)
        if ((data[i] &lt; 0) || (data[i] &gt; 255))
            parts = new int[]{0,0,0,0};
        else
            parts[i] = data[i];
}
</code></pre>

<p>is all I have so far. What could I be missing? </p>

<p>EDIT: made one simple change: </p>

<pre><code>for (int i = 0; i &lt;= data.length; i++)
</code></pre>

<p>to</p>

<pre><code>for (int i = 0; i &lt; data.length; i++)
</code></pre>

<p>And a JUnit test </p>

<pre><code>    public void testSetPartsIntArray() {
    correct1.setParts(new int[]{12, 14, 16, 18});
    int[] a = correct1.getParts();
    assertEquals(4, a.length);
    assertEquals(12, a[0]);
    assertEquals(14, a[1]);
    assertEquals(16, a[2]);
    assertEquals(18, a[3]); 

    correct1.setParts(new int[]{-12, 14, 16, 18});
    a = correct1.getParts();
    assertEquals(4, a.length);
    assertEquals(0, a[0]);
    assertEquals(0, a[1]);
    assertEquals(0, a[2]);
    assertEquals(0, a[3]);  
</code></pre>

<p>works UNTIL </p>

<pre><code>assertEquals(0, a[1]);
</code></pre>

<p>What is causing it to stop there?</p>