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