Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/mxbean/ThreadMXBeanTest.java
38840 views
/*1* Copyright (c) 2005, 2008, 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 630574626* @summary Test that the null values returned by the ThreadMXBean work.27* @author Eamonn McManus28* @run clean ThreadMXBeanTest29* @run build ThreadMXBeanTest30* @run main ThreadMXBeanTest31* @key randomness32*/3334import java.lang.management.*;35import java.util.*;36import javax.management.*;3738public class ThreadMXBeanTest {39public static void main(String[] args) throws Exception {40MBeanServer mbs = MBeanServerFactory.newMBeanServer();41ThreadMXBean tmb = ManagementFactory.getThreadMXBean();42StandardMBean smb = new StandardMBean(tmb, ThreadMXBean.class, true);43ObjectName on = new ObjectName("a:type=ThreadMXBean");44mbs.registerMBean(smb, on);45ThreadMXBean proxy = JMX.newMXBeanProxy(mbs, on, ThreadMXBean.class);46long[] ids1 = proxy.getAllThreadIds();4748// Add some random ids to the list so we'll get back null ThreadInfo49long[] ids2 = new long[ids1.length + 10];50System.arraycopy(ids1, 0, ids2, 0, ids1.length);51Random r = new Random();52for (int i = ids1.length; i < ids2.length; i++)53ids2[i] = Math.abs(r.nextLong());54// Following line produces an exception if null values not handled55ThreadInfo[] info = proxy.getThreadInfo(ids2);56boolean sawNull = false;57for (ThreadInfo ti : info) {58if (ti == null)59sawNull = true;60}61if (!sawNull)62throw new Exception("No null value in returned array");63System.out.println("TEST PASSED");64}65}666768