author | alanb |
Thu, 01 Dec 2016 08:57:53 +0000 | |
changeset 42338 | a60f280f803c |
parent 39130 | bb2660863cbf |
permissions | -rw-r--r-- |
39130
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
1 |
/* |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
4 |
* |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
8 |
* |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
13 |
* accompanied this code). |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
14 |
* |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
18 |
* |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
21 |
* questions. |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
22 |
*/ |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
23 |
|
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
24 |
/** |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
25 |
* @test |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
26 |
* @bug 8158802 |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
27 |
* @summary com.sun.jndi.ldap.SimpleClientId produces wrong hash code |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39130
diff
changeset
|
28 |
* @modules java.naming/com.sun.jndi.ldap:open |
39130
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
29 |
*/ |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
30 |
|
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
31 |
import java.io.OutputStream; |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
32 |
import java.lang.reflect.Constructor; |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
33 |
import javax.naming.ldap.Control; |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
34 |
|
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
35 |
|
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
36 |
public class SimpleClientIdHashCode { |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
37 |
public static void main(String[] args) throws Throwable { |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
38 |
Class<?> simpleClientIdClass |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
39 |
= Class.forName("com.sun.jndi.ldap.SimpleClientId"); |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
40 |
Constructor<?> init = simpleClientIdClass.getDeclaredConstructor( |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
41 |
int.class, String.class, int.class, String.class, |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
42 |
Control[].class, OutputStream.class, String.class, |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
43 |
String.class, Object.class); |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
44 |
init.setAccessible(true); |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
45 |
|
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
46 |
Object p1 = new byte[]{66,77}; |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
47 |
Object p2 = new char[]{'w','d'}; |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
48 |
Object p3 = "word"; |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
49 |
|
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
50 |
test(init, new byte[]{65}, new byte[]{65}); |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
51 |
test(init, new char[]{'p'}, new char[]{'p'}); |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
52 |
test(init, "pass", "pass"); |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
53 |
test(init, p1, p1); |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
54 |
test(init, p2, p2); |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
55 |
test(init, p3, p3); |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
56 |
test(init, null, null); |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
57 |
} |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
58 |
|
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
59 |
private static void test(Constructor<?> init, Object pass1, Object pass2) |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
60 |
throws Throwable { |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
61 |
|
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
62 |
Object o1 = init.newInstance(1, "host", 3, "", null, System.out, |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
63 |
null, null, pass1); |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
64 |
Object o2 = init.newInstance(1, "host", 3, "", null, System.out, |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
65 |
null, null, pass2); |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
66 |
|
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
67 |
if (!o1.equals(o2)) |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
68 |
throw new RuntimeException("Objects not equal"); |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
69 |
|
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
70 |
if (o1.hashCode() != o2.hashCode()) |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
71 |
throw new RuntimeException("Inconsistent hash codes"); |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
72 |
} |
bb2660863cbf
8158802: com.sun.jndi.ldap.SimpleClientId produces wrong hash code
igerasim
parents:
diff
changeset
|
73 |
} |