< prev index next >

test/jdk/java/util/Collections/ReverseOrder.java

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.
--- 1,7 ---
  /*
!  * Copyright (c) 2002, 2026, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

*** 24,22 ***
--- 24,25 ---
  /*
   * @test
   * @bug 4593209 8001667
   * @summary Reverse comparator was subtly broken
   * @author Josh Bloch
+  * @library /test/lib
   */
  
+ import jdk.test.lib.valueclass.VClass;
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.util.Arrays;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.List;
  
  public class ReverseOrder {
+ 
      static byte[] serialBytes(Object o) {
          try {
              ByteArrayOutputStream bos = new ByteArrayOutputStream();
              ObjectOutputStream oos = new ObjectOutputStream(bos);
              oos.writeObject(o);

*** 77,10 ***
--- 80,15 ---
          Comparator clone = serialClone(cmp);
          List list2 = Arrays.asList(a);
          Collections.sort(list2, clone);
          if (!list2.equals(goldenList))
              throw new Exception(list.toString());
+ 
+         List<VClass> vl = Arrays.asList(new VClass(1, new int[] { 1 }), new VClass(3, new int[] { 3 }), new VClass(2, new int[] { 2 }));
+         Collections.sort(vl, Collections.reverseOrder());
+         if (!vl.equals(Arrays.asList(new VClass(3, new int[] { 3 }), new VClass(2, new int[] { 2 }), new VClass(1, new int[] { 1 }))))
+             throw new RuntimeException("value reverseOrder failed");
      }
  }
  
  class Foo implements Comparable {
      int val;
< prev index next >