Merge sort gives IndexOutOfBoundsException
<p>The code reads from a file a number of cases and the size of the arrays to come then fills an array and sends it to be merge sorted.<br>
The problem is I keep getting <code>index out of bounds</code> and it's killing me...   </p>

<p>My debugger just stopped working on my eclipse. </p>

<pre><code>import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class mergesort {

    public static void mergeSort(int[] array, int first, int last){
        int mid;
        if (first&lt;last){
            mid = (last + first)/2;
            mergeSort(array, first, mid);
            mergeSort(array, mid+1, last);
            merge(array, first, last);
        }
    }

    public static void merge(int[] array, int first, int last){
        int mid = (last-first)/2;
        int[] temp = new int[(last-first)];
        int a1 = first, a2 = mid + 1, current = 0;
        while (a1 &lt;=mid &amp;&amp; a2&lt;=last){
            if (array[a1] &lt;= array[a2])
                temp[current++] = array[a1++];
            else
                temp[current++] = array[a2++];
        }
        for (int i = a1; i&lt;=mid; i++)
            temp[current++] = array[i];
        for (int i = a2; i&lt;=last; i++)
            temp[current++] = array[i];
        for (int i =0; i&lt;temp.length; i++)
            array[first+i] = temp[i];
    }

    public static void main(String[] args) throws FileNotFoundException {
        File file = new File("sort.in");
        Scanner scan = new Scanner(file);
        int n1 = scan.nextInt();
        for (int i = 0; i&lt;n1; i++){
            int[] array =new int[scan.nextInt()];
            for (int j = 0; j&lt;array.length; j++){
                array[j] = scan.nextInt(); 
            }
            mergeSort(array, 0, (array.length)-1);
            for (int j = 0; j&lt;array.length; j++){
                System.out.println(array[j]); 
            }
        }
    }
}
</code></pre>
