author | anashaty |
Thu, 25 Sep 2014 15:57:37 +0400 | |
changeset 27057 | 2202074399cf |
child 31448 | 1066345d2a8a |
permissions | -rw-r--r-- |
27057
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
1 |
/* |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
4 |
* |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
8 |
* |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
13 |
* accompanied this code). |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
14 |
* |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
18 |
* |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
21 |
* questions. |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
22 |
*/ |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
23 |
|
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
24 |
/* @test |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
25 |
@bug 8058473 |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
26 |
@summary "Comparison method violates its general contract" when using Clipboard |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
27 |
Ensure that DataFlavorComparator conforms to Comparator contract |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
28 |
@author Anton Nashatyrev |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
29 |
@run main DataFlavorComparatorTest1 |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
30 |
*/ |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
31 |
import sun.datatransfer.DataFlavorUtil; |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
32 |
|
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
33 |
import java.awt.datatransfer.DataFlavor; |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
34 |
import java.util.Comparator; |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
35 |
|
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
36 |
public class DataFlavorComparatorTest1 { |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
37 |
|
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
38 |
public static void main(String[] args) throws Exception { |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
39 |
String[] mimes = new String[] { |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
40 |
"text/plain", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
41 |
"text/plain; charset=unicode", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
42 |
"text/plain; charset=cp1251", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
43 |
"text/plain; charset=unicode; class=java.io.InputStream", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
44 |
"text/plain; charset=unicode; class=java.io.Serializable", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
45 |
"text/plain; charset=unicode; class=java.lang.Object", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
46 |
"text/plain; class=java.lang.String", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
47 |
"text/plain; class=java.io.Reader", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
48 |
"text/plain; class=java.lang.Object", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
49 |
"text/html", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
50 |
"text/html; charset=unicode", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
51 |
"text/html; charset=cp1251", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
52 |
"text/html; charset=unicode; class=java.io.InputStream", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
53 |
"text/html; charset=unicode; class=java.io.Serializable", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
54 |
"text/html; charset=unicode; class=java.lang.Object", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
55 |
"text/html; class=java.lang.String", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
56 |
"text/html; class=java.io.Reader", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
57 |
"text/html; class=java.lang.Object", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
58 |
"text/unknown", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
59 |
"text/unknown; charset=unicode", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
60 |
"text/unknown; charset=cp1251", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
61 |
"text/unknown; charset=unicode; class=java.io.InputStream", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
62 |
"text/unknown; charset=unicode; class=java.io.Serializable", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
63 |
"text/unknown; charset=unicode; class=java.lang.Object", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
64 |
"text/unknown; class=java.lang.String", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
65 |
"text/unknown; class=java.io.Reader", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
66 |
"text/unknown; class=java.lang.Object", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
67 |
"application/unknown; class=java.io.InputStream", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
68 |
"application/unknown; class=java.lang.Object", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
69 |
"application/unknown", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
70 |
"application/x-java-jvm-local-objectref; class=java.io.InputStream", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
71 |
"application/x-java-jvm-local-objectref; class=java.lang.Object", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
72 |
"application/x-java-jvm-local-objectref", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
73 |
"unknown/flavor", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
74 |
"unknown/flavor; class=java.io.InputStream", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
75 |
"unknown/flavor; class=java.lang.Object", |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
76 |
}; |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
77 |
|
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
78 |
DataFlavor[] flavors = new DataFlavor[mimes.length]; |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
79 |
for (int i = 0; i < flavors.length; i++) { |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
80 |
flavors[i] = new DataFlavor(mimes[i]); |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
81 |
} |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
82 |
|
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
83 |
testComparator(DataFlavorUtil.getDataFlavorComparator(), flavors); |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
84 |
|
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
85 |
System.out.println("Passed."); |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
86 |
} |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
87 |
|
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
88 |
private static void testComparator(Comparator cmp, DataFlavor[] flavs) |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
89 |
throws ClassNotFoundException { |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
90 |
|
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
91 |
for (DataFlavor x: flavs) { |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
92 |
for (DataFlavor y: flavs) { |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
93 |
if (Math.signum(cmp.compare(x,y)) != -Math.signum(cmp.compare(y,x))) { |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
94 |
throw new RuntimeException("Antisymmetry violated: " + x + ", " + y); |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
95 |
} |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
96 |
if (cmp.compare(x,y) == 0 && !x.equals(y)) { |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
97 |
throw new RuntimeException("Equals rule violated: " + x + ", " + y); |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
98 |
} |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
99 |
for (DataFlavor z: flavs) { |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
100 |
if (cmp.compare(x,y) == 0) { |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
101 |
if (Math.signum(cmp.compare(x, z)) != Math.signum(cmp.compare(y, z))) { |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
102 |
throw new RuntimeException("Transitivity (1) violated: " + x + ", " + y + ", " + z); |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
103 |
} |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
104 |
} else { |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
105 |
if (Math.signum(cmp.compare(x, y)) == Math.signum(cmp.compare(y, z))) { |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
106 |
if (Math.signum(cmp.compare(x, y)) != Math.signum(cmp.compare(x, z))) { |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
107 |
throw new RuntimeException("Transitivity (2) violated: " + x + ", " + y + ", " + z); |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
108 |
} |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
109 |
} |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
110 |
} |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
111 |
} |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
112 |
} |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
113 |
} |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
114 |
} |
2202074399cf
8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff
changeset
|
115 |
} |