Here's a bug report we received through the GCC bug tracking system.
It looks like the qsort implementation in java.util.Arrays is broken
for large arrays ;-(

Does anyone know qsort well enough to take a look?

regards

  [ bryce ]

-------- Original Message --------
Subject: java/1895: Libjava: Arrays.sort doesn't work
Resent-Date: 7 Feb 2001 01:46:01 -0000
Resent-From: [EMAIL PROTECTED] (GNATS Filer)
Resent-To: [EMAIL PROTECTED]
Resent-CC: [EMAIL PROTECTED], [EMAIL PROTECTED],
[EMAIL PROTECTED]
Date: 7 Feb 2001 01:43:31 -0000
From: [EMAIL PROTECTED]
Reply-To: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]


>Number:         1895
>Category:       java
>Synopsis:       Libjava: Arrays.sort doesn't work
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Feb 06 17:46:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     [EMAIL PROTECTED]
>Release:        gcc version 2.97 20010206 (experimental)
>Organization:
>Environment:
i686-pc-linux-gnu
>Description:
The Arrays.sort() routines don't seem to work for more
than 12 elements.

>How-To-Repeat:
Just run the program.  It dumps a random array that isn't
sorted even though Arrays.sort() was invoked.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
import java.lang.*;
import java.util.*;
import java.io.*;

class SortTest
{
    public static void printArray(PrintStream out, 
                             String caption, int[] array, int step) 
    {
        out.println(caption);
        for (int i = 0, j = 0; i < array.length; ++i, ++j) {
            if (j == step) { j = 0; out.println(""); }
            out.print(" " + array[i]);
        }
        out.println("");
    }
    
    private static boolean isSorted(int[] array) 
    {
        for (int i = 1; i < array.length; ++i) {
            if (array[i-1] > array[i])
                return false;
        }
        return true;
    }
    
    static int haveArg(String[] args, int i, int def) 
    {
        if (args.length > i)
            return Integer.parseInt(args[i]);
        return def;
    }

    public static void main(String[] args)
    {
        int n = haveArg(args, 0, 100);
        int bound = haveArg(args, 1, 200);
        int times = haveArg(args, 2, 10);
        
        int[] A = new int[n];
        Random rand = new Random();

        int i = 0;
        for (; i < times; ++i) {
            for (int j = 0; j < n; ++j) 
                A[j] = rand.nextInt(bound);

            Arrays.sort(A);

            if (! isSorted(A)) {
                printArray(System.out, "Problem array: " + i, A, 10);
                System.exit(1);
            }
        }
    }
};

Reply via email to