Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/MBeanInfo/MBeanInfoHashCodeNPETest.java
38840 views
/*1* Copyright (c) 2013, 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*/2223import javax.management.MBeanAttributeInfo;24import javax.management.MBeanConstructorInfo;25import javax.management.MBeanInfo;26import javax.management.MBeanNotificationInfo;27import javax.management.MBeanOperationInfo;28import javax.management.MBeanParameterInfo;29import javax.management.modelmbean.DescriptorSupport;30import javax.management.openmbean.SimpleType;3132/*33* @test34* @bug 802366935* @summary Test that hashCode()throws NullPointerException36* @author Shanliang JIANG37* @run clean MBeanInfoHashCodeNPETest38* @run build MBeanInfoHashCodeNPETest39* @run main MBeanInfoHashCodeNPETest40*/41public class MBeanInfoHashCodeNPETest {42private static int failed = 0;4344public static void main(String[] args) throws Exception {45System.out.println("---MBeanInfoHashCodeNPETest-main ...");4647// ----48System.out.println("\n---Testing on MBeanAttributeInfo...");49MBeanAttributeInfo mbeanAttributeInfo = new MBeanAttributeInfo(50null, SimpleType.INTEGER.getClassName(), "description", true, true, false);51test(mbeanAttributeInfo, "class name");5253mbeanAttributeInfo = new MBeanAttributeInfo(54"name", null, "description", true, true, false);55test(mbeanAttributeInfo, "type");5657mbeanAttributeInfo = new MBeanAttributeInfo(58"name", SimpleType.INTEGER.getClassName(), null, true, true, false);59test(mbeanAttributeInfo, "description");6061// ----62System.out.println("\n---Testing on MBeanConstructorInfo...");63MBeanConstructorInfo mbeanConstructorInfo = new MBeanConstructorInfo(64null, "", new MBeanParameterInfo[]{}, new DescriptorSupport());65test(mbeanConstructorInfo, "name");6667mbeanConstructorInfo = new MBeanConstructorInfo(68"", null, new MBeanParameterInfo[]{}, new DescriptorSupport());69test(mbeanConstructorInfo, "description");7071mbeanConstructorInfo = new MBeanConstructorInfo(72"", "", null, new DescriptorSupport());73test(mbeanConstructorInfo, "MBeanParameterInfo");7475mbeanConstructorInfo = new MBeanConstructorInfo(76"", "", new MBeanParameterInfo[]{}, null);77test(mbeanConstructorInfo, "descriptor");7879// ----80System.out.println("\n---Testing on MBeanOperationInfo...");81MBeanOperationInfo mbeanOperationInfo = new MBeanOperationInfo(82null, "description", new MBeanParameterInfo[]{}, "type", 1, new DescriptorSupport());83test(mbeanOperationInfo, "name");8485mbeanOperationInfo = new MBeanOperationInfo(86"name", null, new MBeanParameterInfo[]{}, "type", 1, new DescriptorSupport());87test(mbeanOperationInfo, "description");8889mbeanOperationInfo = new MBeanOperationInfo(90"name", "description", null, "type", 1, new DescriptorSupport());91test(mbeanOperationInfo, "MBeanParameterInfo");9293mbeanOperationInfo = new MBeanOperationInfo(94"name", "description", new MBeanParameterInfo[]{}, null, 1, new DescriptorSupport());95test(mbeanOperationInfo, "type");9697mbeanOperationInfo = new MBeanOperationInfo(98"name", "description", new MBeanParameterInfo[]{}, "type", -1, new DescriptorSupport());99test(mbeanOperationInfo, "native impact");100101mbeanOperationInfo = new MBeanOperationInfo(102"name", "description", new MBeanParameterInfo[]{}, "type", 1, null);103test(mbeanOperationInfo, "Descriptor");104105// ----106System.out.println("\n---Testing on MBeanParameterInfo...");107MBeanParameterInfo mbeanParameterInfo = new MBeanParameterInfo(108null, "type", "description", new DescriptorSupport());109test(mbeanParameterInfo, "name");110111mbeanParameterInfo = new MBeanParameterInfo(112"name", null, "description", new DescriptorSupport());113test(mbeanParameterInfo, "description");114115mbeanParameterInfo = new MBeanParameterInfo(116"name", "type", null, new DescriptorSupport());117test(mbeanParameterInfo, "description");118119mbeanParameterInfo = new MBeanParameterInfo(120"name", "type", "description", null);121test(mbeanParameterInfo, "Descriptor");122123// ----124System.out.println("\n---Testing on MBeanInfo...");125String className = "toto";126String description = "titi";127MBeanAttributeInfo[] attrInfos = new MBeanAttributeInfo[]{};128MBeanConstructorInfo[] constrInfos = new MBeanConstructorInfo[]{};129MBeanOperationInfo[] operaInfos = new MBeanOperationInfo[]{};130MBeanNotificationInfo[] notifInfos = new MBeanNotificationInfo[]{};131132MBeanInfo minfo = new MBeanInfo(null, description, attrInfos, constrInfos, operaInfos, notifInfos);133test(minfo, "class name");134135minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, notifInfos);136test(minfo, "name");137138minfo = new MBeanInfo(className, null, attrInfos, constrInfos, operaInfos, notifInfos);139test(minfo, "description");140141minfo = new MBeanInfo(className, description, null, constrInfos, operaInfos, notifInfos);142test(minfo, "attrInfos");143144minfo = new MBeanInfo(className, description, attrInfos, constrInfos, null, notifInfos);145test(minfo, "operaInfos");146147minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, null);148test(minfo, "notifInfos");149150Thread.sleep(100);151if (failed > 0) {152throw new RuntimeException("Test failed: "+failed);153} else {154System.out.println("---Test: PASSED");155}156}157158private static void test(Object obj, String param) {159try {160obj.hashCode();161System.out.println("OK: "+obj.getClass().getSimpleName()+".hashCode worked with a null "+param);162} catch (NullPointerException npe) {163System.out.println("--->KO!!! "+obj.getClass().getSimpleName()+".hashCode got NPE with a null "+param);164failed++;165}166167try {168obj.toString();169System.out.println("OK: "+obj.getClass().getSimpleName()+".toString worked with a null "+param);170} catch (NullPointerException npe) {171System.out.println("--->KO!!! "+obj.getClass().getSimpleName()+".toString got NPE.");172failed++;173}174}175}176177178