An ugly but non-intrusive workaround, that would not add much overhead for 
usual cases,taking advantage of quadraticness blowing up in stack overflow 
before long:

public class ParanoidSort {    public static void sort(Object[] a) {
        try {
            Arrays.sort(a);
        } catch (StackOverflowError e) {
            // Gone quadratic and array was too long.
            // Falling back to slower but safer sort,
            // hoping that array is not damaged.
            HeapSort.sort(a);
        }
    }
}

Could also catch OOME there but I don't know if it's wise.

-Jeff

Reply via email to