In my "merge" function, in the while loop, the given condition is `a!=null && b!=null`, but when `b` is null, it still enters the while loop and then later gives an error.

```
int[] merge(int[]a, int[]b)
{
    int length = a.length+b.length;
    int[]c = new int[length];
    while (a!=null && b!=null)
    {
        if (a[0]<b[0])
        {
            c[length-1]=a[0];
            a = tail(a);
        }
        else
        {
            c[length-1]=b[0];
            b = tail(b);
        }
    }
    return c;
}

int[] mergeSort(int[]a)
{
    if (a.length==1)
        return a;

    int[] q = new int[a.length];
    int[] l = new int[a.length/2];
    int [] r = new int[a.length-l.length];

    for (int i=0; i<l.length; i++)
    {
        l[i] = a[i];
    }
    for (int i=l.length; i<r.length; i++)
    {
        r[i-l.length] = a[i];
    }
    q = merge(mergeSort(l), mergeSort(r));
    return q;
}

```