Path: blob/master/test/jdk/com/sun/jndi/ldap/SimpleClientIdHashCode.java
41153 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 815880226* @summary com.sun.jndi.ldap.SimpleClientId produces wrong hash code27* @modules java.naming/com.sun.jndi.ldap:open28*/2930import java.io.OutputStream;31import java.lang.reflect.Constructor;32import javax.naming.ldap.Control;333435public class SimpleClientIdHashCode {36public static void main(String[] args) throws Throwable {37Class<?> simpleClientIdClass38= Class.forName("com.sun.jndi.ldap.SimpleClientId");39Constructor<?> init = simpleClientIdClass.getDeclaredConstructor(40int.class, String.class, int.class, String.class,41Control[].class, OutputStream.class, String.class,42String.class, Object.class);43init.setAccessible(true);4445Object p1 = new byte[]{66,77};46Object p2 = new char[]{'w','d'};47Object p3 = "word";4849test(init, new byte[]{65}, new byte[]{65});50test(init, new char[]{'p'}, new char[]{'p'});51test(init, "pass", "pass");52test(init, p1, p1);53test(init, p2, p2);54test(init, p3, p3);55test(init, null, null);56}5758private static void test(Constructor<?> init, Object pass1, Object pass2)59throws Throwable {6061Object o1 = init.newInstance(1, "host", 3, "", null, System.out,62null, null, pass1);63Object o2 = init.newInstance(1, "host", 3, "", null, System.out,64null, null, pass2);6566if (!o1.equals(o2))67throw new RuntimeException("Objects not equal");6869if (o1.hashCode() != o2.hashCode())70throw new RuntimeException("Inconsistent hash codes");71}72}737475