Bug6521260.java revision 779:2b61bfcaa586
1/*
2 * Copyright (c) 2014, 2015, 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
24package dom;
25
26import java.io.ByteArrayInputStream;
27import java.io.IOException;
28
29import javax.xml.parsers.DocumentBuilder;
30import javax.xml.parsers.DocumentBuilderFactory;
31import javax.xml.parsers.ParserConfigurationException;
32
33import org.testng.Assert;
34import org.testng.annotations.Test;
35import org.w3c.dom.Document;
36import org.w3c.dom.Element;
37import org.xml.sax.SAXException;
38
39/*
40 * @bug 6521260
41 * @summary Test setAttributeNS doesn't result in an unsorted internal list of attributes.
42 */
43public class Bug6521260 {
44
45    @Test
46    public void test() throws ParserConfigurationException, SAXException, IOException {
47        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
48        factory.setNamespaceAware(true);
49        DocumentBuilder builder = factory.newDocumentBuilder();
50
51        String docStr = "<system systemId='http://www.w3.org/2001/rddl/rddl-xhtml.dtd'" + " uri='/cache/data/xrc36316.bin'"
52                + " xmlns:xr='urn:oasis:names:tc:entity:xmlns:xml:catalog'" + " xr:systemId='http://www.w3.org/2001/rddl/rddl-xhtml.dtd'"
53                + " xmlns:NS1='http://xmlresolver.org/ns/catalog'" + " NS1:time='1170267571097'/>";
54
55        ByteArrayInputStream bais = new ByteArrayInputStream(docStr.getBytes());
56
57        Document doc = builder.parse(bais);
58
59        Element root = doc.getDocumentElement();
60
61        String systemId = root.getAttribute("systemId");
62
63        // Change the prefix on the "time" attribute so that the list would
64        // become unsorted
65        // before my fix to
66        // xml-xerces/java/src/com/sun/org/apache/xerces/internal/dom/ElementImpl.java
67        root.setAttributeNS("http://xmlresolver.org/ns/catalog", "xc:time", "100");
68
69        String systemId2 = root.getAttribute("systemId");
70
71        Assert.assertEquals(systemId, systemId2);
72    }
73}
74