8287076: Document.normalizeDocument() produces different results
Reviewed-by: lancea, iris, naoto
This commit is contained in:
parent
a716f7934b
commit
1f9521e6cb
src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom
test/jaxp/javax/xml/jaxp/unittest/dom
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
@ -39,7 +39,7 @@ import org.w3c.dom.Node;
|
||||
*
|
||||
* @xerces.internal
|
||||
*
|
||||
* @LastModified: Oct 2017
|
||||
* @LastModified: June 2022
|
||||
*/
|
||||
public class AttributeMap extends NamedNodeMapImpl {
|
||||
|
||||
@ -117,7 +117,7 @@ public class AttributeMap extends NamedNodeMapImpl {
|
||||
} else {
|
||||
i = -1 - i; // Insert point (may be end of list)
|
||||
if (null == nodes) {
|
||||
nodes = new ArrayList<>(5);
|
||||
nodes = new ArrayList<>();
|
||||
}
|
||||
nodes.add(i, arg);
|
||||
}
|
||||
@ -193,7 +193,7 @@ public class AttributeMap extends NamedNodeMapImpl {
|
||||
} else {
|
||||
i = -1 - i; // Insert point (may be end of list)
|
||||
if (null == nodes) {
|
||||
nodes = new ArrayList<>(5);
|
||||
nodes = new ArrayList<>();
|
||||
}
|
||||
nodes.add(i, arg);
|
||||
}
|
||||
@ -591,7 +591,7 @@ public class AttributeMap extends NamedNodeMapImpl {
|
||||
else {
|
||||
i = -1 - i; // Insert point (may be end of list)
|
||||
if (null == nodes) {
|
||||
nodes = new ArrayList<>(5);
|
||||
nodes = new ArrayList<>();
|
||||
}
|
||||
nodes.add(i, arg);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
@ -89,7 +89,7 @@ import org.w3c.dom.Text;
|
||||
*
|
||||
* @author Elena Litani, IBM
|
||||
* @author Neeraj Bajaj, Sun Microsystems, inc.
|
||||
* @LastModified: Apr 2019
|
||||
* @LastModified: June 2022
|
||||
*/
|
||||
public class DOMNormalizer implements XMLDocumentHandler {
|
||||
|
||||
@ -140,9 +140,6 @@ public class DOMNormalizer implements XMLDocumentHandler {
|
||||
/** Stores all namespace bindings on the current element */
|
||||
protected final NamespaceContext fLocalNSBinder = new NamespaceSupport();
|
||||
|
||||
/** list of attributes */
|
||||
protected final List<Node> fAttributeList = new ArrayList<>(5);
|
||||
|
||||
/** DOM Locator - for namespace fixup algorithm */
|
||||
protected final DOMLocatorImpl fLocator = new DOMLocatorImpl();
|
||||
|
||||
@ -885,9 +882,9 @@ public class DOMNormalizer implements XMLDocumentHandler {
|
||||
if (attributes != null) {
|
||||
|
||||
// clone content of the attributes
|
||||
attributes.cloneMap(fAttributeList);
|
||||
for (int i = 0; i < fAttributeList.size(); i++) {
|
||||
Attr attr = (Attr) fAttributeList.get(i);
|
||||
List<Node> attrList = attributes.cloneMap(new ArrayList<>());
|
||||
for (int i = 0; i < attrList.size(); i++) {
|
||||
Attr attr = (Attr) attrList.get(i);
|
||||
fLocator.fRelatedNode = attr;
|
||||
|
||||
if (DEBUG) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
@ -56,7 +56,7 @@ import org.w3c.dom.Node;
|
||||
* @xerces.internal
|
||||
*
|
||||
* @since PR-DOM-Level-1-19980818.
|
||||
* @LastModified: Jan 2018
|
||||
* @LastModified: June 2022
|
||||
*/
|
||||
public class NamedNodeMapImpl
|
||||
implements NamedNodeMap, Serializable {
|
||||
@ -197,7 +197,7 @@ public class NamedNodeMapImpl
|
||||
} else {
|
||||
i = -1 - i; // Insert point (may be end of list)
|
||||
if (null == nodes) {
|
||||
nodes = new ArrayList<>(5);
|
||||
nodes = new ArrayList<>();
|
||||
}
|
||||
nodes.add(i, arg);
|
||||
}
|
||||
@ -247,7 +247,7 @@ public class NamedNodeMapImpl
|
||||
} else {
|
||||
i = -1 - i; // Insert point (may be end of list)
|
||||
if (null == nodes) {
|
||||
nodes = new ArrayList<>(5);
|
||||
nodes = new ArrayList<>();
|
||||
}
|
||||
nodes.add(i, arg);
|
||||
}
|
||||
@ -562,7 +562,7 @@ public class NamedNodeMapImpl
|
||||
else {
|
||||
i = -1 - i; // Insert point (may be end of list)
|
||||
if (null == nodes) {
|
||||
nodes = new ArrayList<>(5);
|
||||
nodes = new ArrayList<>();
|
||||
}
|
||||
nodes.add(i, arg);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -34,15 +34,20 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
|
||||
import org.w3c.dom.events.Event;
|
||||
import org.w3c.dom.events.EventListener;
|
||||
import org.w3c.dom.ls.DOMImplementationLS;
|
||||
import org.w3c.dom.ls.LSInput;
|
||||
import org.w3c.dom.ls.LSParser;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8213117 8222743
|
||||
* @bug 8213117 8222743 8287076
|
||||
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
|
||||
* @modules java.xml
|
||||
* @modules java.xml/com.sun.org.apache.xerces.internal.dom
|
||||
@ -56,6 +61,53 @@ public class DocumentTest {
|
||||
static final int DOC1 = 1;
|
||||
static final int DOC2 = 2;
|
||||
|
||||
/*
|
||||
* @bug 8287076
|
||||
* Verifies that Document::normalizeDocument returns the same result as that
|
||||
* prior to JDK 10 (JDK-8181150).
|
||||
* Attribute Name:
|
||||
* JDK 9: NS1:wsu and NS2:wsu2
|
||||
* After the JDK 10 change: wsu and wsu2
|
||||
*/
|
||||
@Test
|
||||
public void testNormalizeDocument() throws Exception {
|
||||
final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
|
||||
final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
|
||||
final LSParser builder = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
|
||||
final LSInput input = impl.createLSInput();
|
||||
input.setStringData("<xml/>");
|
||||
final Document document = builder.parse(input);
|
||||
final Element root = document.getDocumentElement();
|
||||
|
||||
// Generate a single element
|
||||
final Element element = document.createElement("token");
|
||||
final Attr attr = element.getOwnerDocument().createAttributeNS("http://blah.xsd", "wsu");
|
||||
attr.setValue("Id");
|
||||
element.setAttributeNodeNS(attr);
|
||||
|
||||
final Attr attr2 = element.getOwnerDocument().createAttributeNS("http://blah2.xsd", "wsu2");
|
||||
element.setAttributeNodeNS(attr2);
|
||||
|
||||
final Attr attr3 = element.getOwnerDocument().createAttribute("aa");
|
||||
element.setAttributeNodeNS(attr3);
|
||||
|
||||
final Attr attr4 = element.getOwnerDocument().createAttribute("zz");
|
||||
element.setAttributeNodeNS(attr4);
|
||||
|
||||
final Attr attr5 = element.getOwnerDocument().createAttribute("tt");
|
||||
element.setAttributeNodeNS(attr5);
|
||||
|
||||
root.appendChild(element);
|
||||
|
||||
document.normalizeDocument();
|
||||
|
||||
Node wsu = element.getAttributes().getNamedItemNS("http://blah.xsd", "wsu");
|
||||
Node wsu2 = element.getAttributes().getNamedItemNS("http://blah2.xsd", "wsu2");
|
||||
|
||||
Assert.assertEquals(wsu.getNodeName(), "NS1:wsu");
|
||||
Assert.assertEquals(wsu2.getNodeName(), "NS2:wsu2");
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the adoptNode method. Before a node from a deferred DOM can be
|
||||
* adopted, it needs to be fully expanded.
|
||||
|
Loading…
x
Reference in New Issue
Block a user