I get a null pointer at:
n[Array.getLength(n)-1] = cur;
not an arrayIndexOutOfBounds, but a null pointer? I didn't think you get get a null pointer on assignment, because after all aren't you supposed to be able to assign any object a null?
EDIT: n is a non primitive type. It is actually an array of objects.