webpro2 / javapns

Automatically exported from code.google.com/p/javapns
0 stars 0 forks source link

NotificationThreads's groupDevices method throwing IllegalArgumentException #71

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
hi, there is something wrong at 
"javapns.notification.transmission.NotificationThreads"
...
private List<List<Device>> groupDevices(List<Device> devices, int threads);

/////////////////////////////////////////////
public class Test {

    public static void main(String[] args) throws Exception {

        for (int n = 10; n < 10000; n++) {
            List<Device> devices = new ArrayList<Device>();
            for (int i = 0; i < n; i++) {
                devices.add(new BasicDevice("123456789012345678901234567890123456789012345678901234567" + (1000000 + i)));
            }
            try {
                groupDevices(devices, 10);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
                System.out.println("............n=" + n);
            }
        }
    }

    private static List<List<Device>> groupDevices(List<Device> devices, int threads) {
        List<List<Device>> groups = new Vector<List<Device>>();
        int total = devices.size();
        int devicesPerThread = (total / threads);
        if (total % threads > 0) devicesPerThread++;
        for (int i = 0; i < threads; i++) {
            int firstDevice = i * devicesPerThread;
            int lastDevice = firstDevice + devicesPerThread - 1;
            if (lastDevice >= total) lastDevice = total - 1;
            List<Device> threadDevices = devices.subList(firstDevice, lastDevice + 1);
            groups.add(threadDevices);
        }
        return groups;
    }

}

//////////////////////////////////////////////////////////

See the result above you will find the problem.

Original issue reported on code.google.com by ypf327...@gmail.com on 30 Sep 2011 at 10:06

GoogleCodeExporter commented 9 years ago
Thank you for reporting the issue.  It was reproduced with the test case you 
provided and a fix will be issued shortly.

Original comment by sype...@gmail.com on 30 Sep 2011 at 2:59

GoogleCodeExporter commented 9 years ago

Original comment by sype...@gmail.com on 30 Sep 2011 at 3:00

GoogleCodeExporter commented 9 years ago
Fixed in 2.0 RC Revision 001, which you can download as of now from the source:
http://code.google.com/p/javapns/source/browse/#svn%2Fbranches%2Fjavapns2

Original comment by sype...@gmail.com on 30 Sep 2011 at 10:21

GoogleCodeExporter commented 9 years ago
thanks for your efforts

Original comment by ypf327...@gmail.com on 8 Oct 2011 at 1:44