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