Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/loading/ParserInfiniteLoopTest.java
38838 views
1
/*
2
* Copyright (c) 2005, 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 5042364
27
* @summary Malformed MLet text file causes infinite loop in parser.
28
* The MLetParser goes into an infinite loop when a tag is not
29
* terminated with the corresponding '>' and an opening '<' for
30
* the subsequent tag is encountered.
31
* @author Luis-Miguel Alventosa
32
* @run clean ParserInfiniteLoopTest
33
* @run build ParserInfiniteLoopTest
34
* @run main/othervm ParserInfiniteLoopTest mlet1.html
35
* @run main/othervm ParserInfiniteLoopTest mlet2.html
36
* @run main/othervm ParserInfiniteLoopTest mlet3.html
37
*/
38
39
import java.io.File;
40
import java.io.IOException;
41
import javax.management.MBeanServer;
42
import javax.management.MBeanServerFactory;
43
import javax.management.ObjectName;
44
import javax.management.ServiceNotFoundException;
45
import javax.management.loading.MLet;
46
47
public class ParserInfiniteLoopTest {
48
49
public static void main(String[] args) throws Exception {
50
51
boolean error = false;
52
53
// Instantiate the MBean server
54
//
55
System.out.println("Create the MBean server");
56
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
57
58
// Instantiate an MLet
59
//
60
System.out.println("Create the MLet");
61
MLet mlet = new MLet();
62
63
// Register the MLet MBean with the MBeanServer
64
//
65
System.out.println("Register the MLet MBean");
66
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
67
mbs.registerMBean(mlet, mletObjectName);
68
69
// Call getMBeansFromURL
70
//
71
System.out.println("Call mlet.getMBeansFromURL(<url>)");
72
String testSrc = System.getProperty("test.src");
73
System.out.println("test.src = " + testSrc);
74
String urlCodebase;
75
if (testSrc.startsWith("/")) {
76
urlCodebase =
77
"file:" + testSrc.replace(File.separatorChar, '/') + "/";
78
} else {
79
urlCodebase =
80
"file:/" + testSrc.replace(File.separatorChar, '/') + "/";
81
}
82
String mletFile = urlCodebase + args[0];
83
System.out.println("MLet File = " + mletFile);
84
try {
85
mlet.getMBeansFromURL(mletFile);
86
System.out.println(
87
"TEST FAILED: Expected ServiceNotFoundException not thrown");
88
error = true;
89
} catch (ServiceNotFoundException e) {
90
if (e.getCause() == null) {
91
System.out.println("TEST FAILED: Got unexpected null cause " +
92
"in ServiceNotFoundException");
93
error = true;
94
} else if (!(e.getCause() instanceof IOException)) {
95
System.out.println("TEST FAILED: Got unexpected non-null " +
96
"cause in ServiceNotFoundException");
97
error = true;
98
} else {
99
System.out.println("TEST PASSED: Got expected non-null " +
100
"cause in ServiceNotFoundException");
101
error = false;
102
}
103
e.printStackTrace(System.out);
104
}
105
106
// Unregister the MLet MBean
107
//
108
System.out.println("Unregister the MLet MBean");
109
mbs.unregisterMBean(mletObjectName);
110
111
// Release MBean server
112
//
113
System.out.println("Release the MBean server");
114
MBeanServerFactory.releaseMBeanServer(mbs);
115
116
// End Test
117
//
118
System.out.println("Bye! Bye!");
119
if (error) System.exit(1);
120
}
121
}
122
123