Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6518733
Votes 0
Synopsis Regression: SAX not correctly handling attributes with newlines
Category jaxp:sax
Reported Against
Release Fixed 1.4, 7(b14) (Bug ID:2153415) , 6u13-rev(b07) (Bug ID:2175113) , 6u14(b06) (Bug ID:2176416)
State 11-Closed, Verified, bug
Priority: 4-Low
Related Bugs 6582545 , 6690015 , 6760982
Submit Date 29-JAN-2007
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 :
 customer  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.
Posted Date : 2007-01-29 17:46:48.0
Work Around
N/A
Evaluation
This was due to a caching issue internally in Xerces. A patch has been committed to our Java.net workspace.
Posted Date : 2007-01-29 22:39:58.0
Comments
  
  Include a link with my name & email   

Submitted On 17-JAN-2008
skaushik
I have seen similar issue with jre1.6.0_04. The workaround is to use xercesImpl.jar (version 2.9.1) instead.


Submitted On 22-OCT-2009
I have tested JRE 60.-16. I have same problem....

It is really fixed?????


Submitted On 23-OCT-2009
spericas
I've just verified 3 tests related to this issue and they *all* pass on 1.6.0_16 (Solaris x86). Can you double check your JDK version? Do you have any jars in your endorsed directory or bootclasspath? Can you send us a test case to reproduce the problem?



PLEASE NOTE: JDK6 is formerly known as Project Mustang