Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/loading/ParserInfiniteLoopTest.java
38838 views
/*1* Copyright (c) 2005, 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 504236426* @summary Malformed MLet text file causes infinite loop in parser.27* The MLetParser goes into an infinite loop when a tag is not28* terminated with the corresponding '>' and an opening '<' for29* the subsequent tag is encountered.30* @author Luis-Miguel Alventosa31* @run clean ParserInfiniteLoopTest32* @run build ParserInfiniteLoopTest33* @run main/othervm ParserInfiniteLoopTest mlet1.html34* @run main/othervm ParserInfiniteLoopTest mlet2.html35* @run main/othervm ParserInfiniteLoopTest mlet3.html36*/3738import java.io.File;39import java.io.IOException;40import javax.management.MBeanServer;41import javax.management.MBeanServerFactory;42import javax.management.ObjectName;43import javax.management.ServiceNotFoundException;44import javax.management.loading.MLet;4546public class ParserInfiniteLoopTest {4748public static void main(String[] args) throws Exception {4950boolean error = false;5152// Instantiate the MBean server53//54System.out.println("Create the MBean server");55MBeanServer mbs = MBeanServerFactory.createMBeanServer();5657// Instantiate an MLet58//59System.out.println("Create the MLet");60MLet mlet = new MLet();6162// Register the MLet MBean with the MBeanServer63//64System.out.println("Register the MLet MBean");65ObjectName mletObjectName = new ObjectName("Test:type=MLet");66mbs.registerMBean(mlet, mletObjectName);6768// Call getMBeansFromURL69//70System.out.println("Call mlet.getMBeansFromURL(<url>)");71String testSrc = System.getProperty("test.src");72System.out.println("test.src = " + testSrc);73String urlCodebase;74if (testSrc.startsWith("/")) {75urlCodebase =76"file:" + testSrc.replace(File.separatorChar, '/') + "/";77} else {78urlCodebase =79"file:/" + testSrc.replace(File.separatorChar, '/') + "/";80}81String mletFile = urlCodebase + args[0];82System.out.println("MLet File = " + mletFile);83try {84mlet.getMBeansFromURL(mletFile);85System.out.println(86"TEST FAILED: Expected ServiceNotFoundException not thrown");87error = true;88} catch (ServiceNotFoundException e) {89if (e.getCause() == null) {90System.out.println("TEST FAILED: Got unexpected null cause " +91"in ServiceNotFoundException");92error = true;93} else if (!(e.getCause() instanceof IOException)) {94System.out.println("TEST FAILED: Got unexpected non-null " +95"cause in ServiceNotFoundException");96error = true;97} else {98System.out.println("TEST PASSED: Got expected non-null " +99"cause in ServiceNotFoundException");100error = false;101}102e.printStackTrace(System.out);103}104105// Unregister the MLet MBean106//107System.out.println("Unregister the MLet MBean");108mbs.unregisterMBean(mletObjectName);109110// Release MBean server111//112System.out.println("Release the MBean server");113MBeanServerFactory.releaseMBeanServer(mbs);114115// End Test116//117System.out.println("Bye! Bye!");118if (error) System.exit(1);119}120}121122123