Skip to content

Commit e6902cf

Browse files
committedJan 14, 2025
8323740: java.lang.ExceptionInInitializerError when trying to load XML classes in wrong order
Reviewed-by: joehw
1 parent a01e92c commit e6902cf

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed
 

‎src/java.xml/share/classes/jdk/xml/internal/JdkXmlUtils.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ public class JdkXmlUtils {
9494
/**
9595
* The system-default factory
9696
*/
97-
private static final SAXParserFactory defaultSAXFactory = getSAXFactory(false);
97+
private static class DefaultSAXFactory {
98+
private static final SAXParserFactory instance = getSAXFactory(false);
99+
}
98100

99101
/**
100102
* Returns the value.
@@ -322,7 +324,7 @@ public static XMLReader getXMLReader(XMLSecurityManager sm,
322324
}
323325
} else {
324326
// use the system-default
325-
saxFactory = defaultSAXFactory;
327+
saxFactory = DefaultSAXFactory.instance;
326328

327329
try {
328330
reader = saxFactory.newSAXParser().getXMLReader();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2024, Google LLC. 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+
import org.testng.annotations.Test;
25+
26+
import java.util.Objects;
27+
28+
/**
29+
* @test
30+
*
31+
* @bug 8323740
32+
* @summary test that class initializers don't crash
33+
* @run testng/othervm InitializerTest
34+
*/
35+
public class InitializerTest {
36+
37+
@Test
38+
public void testXMLOutputFactory() throws Exception {
39+
String name = "com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl";
40+
Objects.requireNonNull(Class.forName(name));
41+
}
42+
}

0 commit comments

Comments
 (0)
Please sign in to comment.