JDK-6518733 : Regression: SAX not correctly handling attributes with newlines
  • Type: Bug
  • Component: xml
  • Sub-Component: org.xml.sax
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: linux,windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2007-01-29
  • Updated: 2012-04-25
  • Resolved: 2007-01-29
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.
Other JDK 6 JDK 7
1.4.0 1.4Fixed 6u13-revFixed 7Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]


A DESCRIPTION OF THE PROBLEM :
org.xml.sax.Attributes.getValue(int) sometimes returns the wrong value.  This has been noticed when reading an XML file containing several attributes that each contain a newline within the attribute value.  Removing the newlines from an attribute can effect the value that is returned for a subsequent attribute.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the program provided, which reads the XML file provided.  The program expects the file to be in C:\, which is hard coded.  Change the source code to point to the location where you place the XML file.  The program reads each attribute name and value and writes them out.  Attrubute 7 shows the value from attribute 8.  If the XML file is edited and the newline is removed from attribute 1, then attribute 7's value is correct, but attribute 8 shows the value from attribute 9.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When running the code below on the XML file below, each attribute correctly reports the corresponding value.
-------------------------------------------------
Output from Java 1.5.0_09
-------------------------------------------------
QName = q1    Value = 1 A
QName = q2    Value = 2 B
QName = q3    Value = 3 C
QName = q4    Value = 4 D
QName = q5    Value = 5 E
QName = q6    Value = 6 F
QName = q7    Value = 7 G
QName = q8    Value = 8 H
QName = q9    Value = 9 I

ACTUAL -
When running the code below on the XML file below, attribute 7 reports the value for attribute 8.
-------------------------------------------------
Output from Java 1.6.0
-------------------------------------------------
QName = q1    Value = 1 A
QName = q2    Value = 2 B
QName = q3    Value = 3 C
QName = q4    Value = 4 D
QName = q5    Value = 5 E
QName = q6    Value = 6 F
QName = q7    Value = 8 H
QName = q8    Value = 8 H
QName = q9    Value = 9 I


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
-------------------------------------------------
testSAX.java
-------------------------------------------------
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class TestSAX  extends org.xml.sax.helpers.DefaultHandler {
    
    public TestSAX() {
    }
 
    public void startElement (String uri, String localName, String qName,
        Attributes attrs) throws SAXException {

        if (attrs != null) {
            for (int i = 0; i < attrs.getLength(); i++) {
                System.out.print("QName = " + attrs.getQName(i) + "    ");
                System.out.println("Value = " + attrs.getValue(i));
            }
        }

    }

    static public void main (String args[]) {

	SAXParserFactory factory = SAXParserFactory.newInstance();
        try {
            SAXParser saxParser = factory.newSAXParser();
            saxParser.parse(new InputSource(new FileReader(
                "C:\\test.xml"))
                , new TestSAX());
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (ParserConfigurationException ex) {
            ex.printStackTrace();
        } catch (SAXException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }
    
}


-------------------------------------------------
test.xml
-------------------------------------------------
<?xml version="1.0"?>

<obj

q1="1
A"

q2="2
B"

q3="3
C"

q4="4
D"

q5="5
E"

q6="6
F"

q7="7
G"

q8="8
H"

q9="9
I"

/>


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

CUSTOMER SUBMITTED WORKAROUND :
None, from the source code side.  Java 5.0 can be used, but the app has already started using Java 6 libraries in some classes.  The XML files can be changed, as the newlines are only used for lining up values in an ASCII editor, but this would be time consuming since many files were created when the app was running on Java 5.0.

Comments
EVALUATION This was due to a caching issue internally in Xerces. A patch has been committed to our Java.net workspace.
29-01-2007