Skip to content

Commit

Permalink
[FIXED JENKINS-26690] Integer overflow in AbstractLazyLoadRunMap.head…
Browse files Browse the repository at this point in the history
…Map with negative arguments.
  • Loading branch information
jglick committed Feb 26, 2015
1 parent 3e920a9 commit db1f805
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Expand Up @@ -550,7 +550,7 @@ public boolean equals(Object o) {

private static final Comparator<Integer> COMPARATOR = new Comparator<Integer>() {
@Override public int compare(Integer o1, Integer o2) {
return o2 - o1;
return -o1.compareTo(o2);
}
};

Expand Down
Expand Up @@ -40,7 +40,6 @@
import java.util.logging.Level;
import org.junit.BeforeClass;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.Issue;

/**
* @author Kohsuke Kawaguchi
Expand Down Expand Up @@ -133,6 +132,21 @@ public void firstKey() {
}
}

@Issue("JENKINS-26690")
@Test public void headMap() {
assertEquals("[]", a.headMap(Integer.MAX_VALUE).keySet().toString());
assertEquals("[]", a.headMap(6).keySet().toString());
assertEquals("[]", a.headMap(5).keySet().toString());
assertEquals("[5]", a.headMap(4).keySet().toString());
assertEquals("[5]", a.headMap(3).keySet().toString());
assertEquals("[5, 3]", a.headMap(2).keySet().toString());
assertEquals("[5, 3]", a.headMap(1).keySet().toString());
assertEquals("[5, 3, 1]", a.headMap(0).keySet().toString());
assertEquals("[5, 3, 1]", a.headMap(-1).keySet().toString());
assertEquals("[5, 3, 1]", a.headMap(-2).keySet().toString()); // this failed
assertEquals("[5, 3, 1]", a.headMap(Integer.MIN_VALUE).keySet().toString());
}

@Test
public void lastKey() {
assertEquals(1, a.lastKey().intValue());
Expand Down

0 comments on commit db1f805

Please sign in to comment.