-
Bug
-
Resolution: Fixed
-
P3
-
10, 11, 17, 18, 19
-
b28
-
b29
-
generic
-
generic
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8289239 | 20 | Joe Wang | P3 | Resolved | Fixed | b04 |
JDK-8291314 | 19.0.2 | Joe Wang | P3 | Resolved | Fixed | b01 |
JDK-8291145 | 19.0.1 | Joe Wang | P3 | Resolved | Fixed | b04 |
JDK-8293147 | 17.0.6-oracle | Weibing Xiao | P3 | Resolved | Fixed | b01 |
JDK-8294614 | 17.0.6 | Victor Rudometov | P3 | Resolved | Fixed | b01 |
JDK-8298453 | 15.0.10 | Yuri Nesterenko | P3 | Resolved | Fixed | b04 |
JDK-8298452 | 13.0.14 | Yuri Nesterenko | P3 | Resolved | Fixed | b04 |
JDK-8293145 | 11.0.18-oracle | Weibing Xiao | P3 | Resolved | Fixed | b01 |
JDK-8294613 | 11.0.18 | Victor Rudometov | P3 | Resolved | Fixed | b01 |
JDK 9.0.4 - works
JDK 10.0 onwards (including 18) - cloneMap returns empty list
A DESCRIPTION OF THE PROBLEM :
I was upgrading from Java 8 (works fine) to 11 calculating a digest value on an XML snippet. I was getting different result. Document.normalizeDocument returns different results when crossing over fro 9.0.4 to 10.0 onwards.
To pin point the bug. observer the call:
DOMNormalizer.namespaceFixUp()
Line 888: attributes.cloneMap(fAttributeList);
cloneMap does NOT work. NOTE this does not use the return value and replies on fAttributeList being passed by reference.
The implementation of clone map NamedNodeMapImpl.cloneMap():578 has changed.
Line 580: list = new ArrayList<>(nodes);
This news the method parameter which leaves the reference passed in by DOMNormalizer empty. This worked fine on JDK 9.0.4.
Really the code should be:
fAttributeList = attributes.cloneMap(fAttributeList);
OR the implementation change back
REGRESSION : Last worked in version 8u331
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the source code provider under JDK 9.0.4 and a more recent JDK 10+. Different namespace attribute ordering because NamedNodeMapImpl.cloneMap is not working as intended.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected consistent results and the fAttributeList to be populated from cloneMap.
ACTUAL -
cloneMap is not populating variable fAttributeList
---------- BEGIN SOURCE ----------
package test;
import java.io.StringWriter;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSParser;
import org.w3c.dom.ls.LSSerializer;
public class main {
public static void main(final String[] args) {
try
{
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);
for ( int i = 0; i < element.getAttributes().getLength(); i++ )
{
System.out.println(element.getAttributes().item(i).getNodeName());
}
//final String originalXML = prettyPrintFromDocument(document);
System.out.println("PRE normalise " + prettyPrintFromDocument(document));
document.normalizeDocument();
System.out.println("POST normalise " + prettyPrintFromDocument(document));
for ( int i = 0; i < element.getAttributes().getLength(); i++ )
{
System.out.println(element.getAttributes().item(i).getNodeName());
}
}
catch ( final Exception ex )
{
ex.printStackTrace();
}
}
/**
* Pretty prints a DOM document to a String.
*
* @param message the DOM document to serialise.
* @return a string representation of the DOM message parameter.
*/
private static String prettyPrintFromDocument(final Document message) {
try {
final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
final LSSerializer writer = impl.createLSSerializer();
final LSOutput output = impl.createLSOutput();
final StringWriter sw = new StringWriter();
output.setEncoding("UTF-8");
output.setCharacterStream(sw);
try {
writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
} catch (final Exception ignore) {
}
writer.write(message, output);
return sw.toString();
} catch (final RuntimeException e) {
throw e;
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None at the moment.
Happy to provide more info. Using Eclipse as debugger.
FREQUENCY : always
- backported by
-
JDK-8289239 Document.normalizeDocument() produces different results
- Resolved
-
JDK-8291145 Document.normalizeDocument() produces different results
- Resolved
-
JDK-8291314 Document.normalizeDocument() produces different results
- Resolved
-
JDK-8293145 Document.normalizeDocument() produces different results
- Resolved
-
JDK-8293147 Document.normalizeDocument() produces different results
- Resolved
-
JDK-8294613 Document.normalizeDocument() produces different results
- Resolved
-
JDK-8294614 Document.normalizeDocument() produces different results
- Resolved
-
JDK-8298452 Document.normalizeDocument() produces different results
- Resolved
-
JDK-8298453 Document.normalizeDocument() produces different results
- Resolved
- relates to
-
JDK-8181150 Fix lint warnings in JAXP repo: rawtypes and unchecked
- Resolved
- links to
-
Commit openjdk/jdk11u-dev/2ebb8997
-
Commit openjdk/jdk13u-dev/098f0ea6
-
Commit openjdk/jdk15u-dev/057c00eb
-
Commit openjdk/jdk17u-dev/796628eb
-
Commit openjdk/jdk19/1f9521e6
-
Review openjdk/jdk11u-dev/1372
-
Review openjdk/jdk13u-dev/440
-
Review openjdk/jdk15u-dev/313
-
Review openjdk/jdk17u-dev/738
-
Review openjdk/jdk17u-dev/739
-
Review openjdk/jdk19/59