JDK-8059327 : XML parser returns corrupt attribute value
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.parsers
  • Affected Version: 8u20
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2014-09-26
  • Updated: 2016-11-30
  • Resolved: 2014-11-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7 JDK 8 JDK 9
6u91Fixed 7u76Fixed 8u31Fixed 9 b40Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) Client VM (build 25.20-b23, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
Parsing the XML contained in the sample program provided gives a wrong value "q" for the attribute a1. The correct value is "w".

The problem depends on the &quote; value of the second attribute a2 and the buffer sizes used when parsing the XML. If a previous read stops after "...&q" then the last entity character "q" corrupts the string buffer of the previously read attribute a1. Therefore the attribute a1 returns the value "q" instead of "w".


REGRESSION.  Last worked in version 7u40

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) Client VM (build 25.20-b23, mixed mode, sharing)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Simply run the program attached to this issue and see the output "q".
"w" would be the correct output.



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Attribute "a1" should have the value "w" not "q" as it is with Java 1.7 Update 40
ACTUAL -
Attribute "a1" has value "q".

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.ByteArrayInputStream;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;

public class XMLParserBug {
    public static void main(String[] args) throws Exception {
        Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ChunkInputStream());
        System.out.println(d.getDocumentElement().getAttribute("a1"));
    }
    
    static class ChunkInputStream extends ByteArrayInputStream {
        ChunkInputStream() {
            super("<element a1=\"w\" a2=\"&quot;&quot;\"/>".getBytes());
        }
   
        @Override
        public synchronized int read(byte[] b, int off, int len) {
            return super.read(b, off, 9);
        }
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Change buffer sizes when reading the XML file. This may produce the same problem with other XMLs, since it depends on the XML structure and the buffer sizes.


Comments
SQE OK to take the fix to PSU15_01
19-11-2014

PSU15_01 justification: data corruption, regression.
19-11-2014

Can we have the critical request justification here ?
18-11-2014

What is a justification to have this fix in CPU? P3, not a regression in CPU15_01, introuduced somewhere in LU/PSU, whorkaround exists. Suggest to move it in PSU.
17-11-2014

The issue was introduced in Version 8u20, 7u66 and 6u81.
10-11-2014

Caused by JDK-8027359
05-11-2014

Confirmed with JDK 7u40, 7u67, and 8u20. Result is as explained in the bug. For JDK 7, the attribute value is ''w' and for JDK 8u20 the value is 'q'.
29-09-2014