changeset 1214:bd86dc4dbbb1

7901411: -prof stack sorting is messed up Summary: fix Multisets.countHighest bug.
author shade
date Wed, 29 Apr 2015 23:53:21 +0300
parents 549b2aaf63ca
children 6f73b8573922
files jmh-core/src/main/java/org/openjdk/jmh/util/Multisets.java jmh-core/src/test/java/org/openjdk/jmh/util/MultisetsTest.java
diffstat 2 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/Multisets.java	Fri Apr 24 16:11:05 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/Multisets.java	Wed Apr 29 23:53:21 2015 +0300
@@ -40,7 +40,8 @@
 
         List<T> result = new ArrayList<T>(q.size());
 
-        for (Map.Entry<T, Long> pair : q) {
+        Map.Entry<T, Long> pair;
+        while ((pair = q.poll()) != null) {
             result.add(pair.getKey());
         }
 
--- a/jmh-core/src/test/java/org/openjdk/jmh/util/MultisetsTest.java	Fri Apr 24 16:11:05 2015 +0300
+++ b/jmh-core/src/test/java/org/openjdk/jmh/util/MultisetsTest.java	Wed Apr 29 23:53:21 2015 +0300
@@ -47,6 +47,23 @@
     }
 
     @Test
+    public void testCountHighest_2() {
+        // Regression test for CODETOOLS-7901411
+
+        Multiset<String> set = new HashMultiset<String>();
+        set.add("Meh", 85);
+        set.add("Blah", 17);
+        set.add("Choo", 1);
+
+        List<String> top = Multisets.countHighest(set, 3);
+
+        Assert.assertEquals(3, top.size());
+        Assert.assertEquals("Meh", top.get(0));
+        Assert.assertEquals("Blah", top.get(1));
+        Assert.assertEquals("Choo", top.get(2));
+    }
+
+    @Test
     public void testSortedDesc() {
         Multiset<Integer> set = new HashMultiset<Integer>();
         set.add(10);