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/xml/jaxp/testng/parse/XMLEntityScannerLoad.java
38859 views
1
/*
2
* Copyright (c) 2014, 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
package parse;
25
26
import java.io.ByteArrayInputStream;
27
import java.io.IOException;
28
import javax.xml.parsers.DocumentBuilderFactory;
29
import javax.xml.parsers.ParserConfigurationException;
30
31
import static org.testng.Assert.assertEquals;
32
import org.testng.annotations.DataProvider;
33
import org.testng.annotations.Test;
34
import org.w3c.dom.Document;
35
import org.xml.sax.SAXException;
36
37
/**
38
* JDK-8059327: XML parser returns corrupt attribute value
39
* https://bugs.openjdk.java.net/browse/JDK-8059327
40
*
41
* Also:
42
* JDK-8061550: XMLEntityScanner can corrupt corrupt content during parsing
43
* https://bugs.openjdk.java.net/browse/JDK-8061550
44
*
45
* @Summary: verify that the character cache in XMLEntityScanner is reset properly
46
*/
47
48
public class XMLEntityScannerLoad {
49
50
@Test(dataProvider = "xmls")
51
public void test(String xml) throws SAXException, IOException, ParserConfigurationException {
52
Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ChunkInputStream(xml));
53
String value = d.getDocumentElement().getAttribute("a1");
54
assertEquals(value, "w");
55
}
56
57
static class ChunkInputStream extends ByteArrayInputStream {
58
ChunkInputStream(String xml) {
59
super(xml.getBytes());
60
}
61
62
@Override
63
public synchronized int read(byte[] b, int off, int len) {
64
return super.read(b, off, 7);
65
}
66
}
67
68
@DataProvider(name = "xmls")
69
private Object[][] xmls() {
70
return new Object[][] {
71
{"<?xml version=\"1.0\"?><element a1=\"w\" a2=\"&quot;&quot;\"/>"},
72
{"<?xml version=\"1.1\"?><element a1=\"w\" a2=\"&quot;&quot;\"/>"}
73
};
74
}
75
}
76
77