Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6306295

SAX parser is truncating element values

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 1.4.0
    • 5.0
    • xml

      FULL PRODUCT VERSION :
      On Windows XP:
        1.5.0_04
        1.6.0ea
      On Solaris
        1.5.0_03

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]
      SunOS dogbert 5.8 Generic_117350-05 sun4u sparc SUNW,Ultra-5_10


      A DESCRIPTION OF THE PROBLEM :
      The value of the Name element in the example provided is being truncated.

      What is interesting is that as you test with each successive 'request'
      string, where a level of nesting is removed at each step, more and more
      of the <Name> element appears in nameList_[0].

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the test sources provided in this report.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      On Windows/XP 1.4.1_02: correct
      NameList element[0] ThisIsAReallyBigAndLongClassNameForCurtis
      ACTUAL -
      On Windows/XP 1.5.0_04: incorrect
      NameList element[0] ThisIsAReallyBigAndLong
      NameList element[1] ClassNameForCurtis

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
      TestSAX.java

      Output:

      On Windows/XP
      1.4.1_02: correct
      NameList element[0] ThisIsAReallyBigAndLongClassNameForCurtis

      1.5.0_04: incorrect
      NameList element[0] ThisIsAReallyBigAndLong
      NameList element[1] ClassNameForCurtis

      1.6.0ea: incorrect
      NameList element[0] ThisIsAReallyBigAndLong
      NameList element[1] ClassNameForCurtis

      On Solaris 8:
      1.4.2_03: correct
      NameList element[0] ThisIsAReallyBigAndLongClassNameForCurtis

      1.5.0_03: incorrect
      NameList element[0] ThisIsAReallyBigAndLong
      NameList element[1] ClassNameForCurtis

      What is interesting is that as you test with each successive 'request'
      string, where a level of nesting is removed at each step, more and more
      of the <Name> element appears in nameList_[0].
      */

      import org.xml.sax.Attributes;
      import org.xml.sax.InputSource;
      import org.xml.sax.SAXException;
      import org.xml.sax.helpers.DefaultHandler;

      import javax.xml.parsers.ParserConfigurationException;
      import javax.xml.parsers.SAXParser;
      import javax.xml.parsers.SAXParserFactory;
      import java.io.IOException;
      import java.io.StringReader;
      import java.util.Vector;


      public class TestSAX
      {
      public static final String GET_CLASS_DEF_LIST_REQUEST = "GetClassDefsReq";
      public static final String GET_CLASS_DEF_IGN_CLASSLIST = "ClassList";
      public static final String GET_CLASS_DEF_IGN_CLASS = "Class";

      public class MIMServerDocHandler extends DefaultHandler
      {
      String msgBeingProcessed_ = null;
      boolean confirmed_ = false;
      boolean all_ = true;
      int invokeId_ = -1;
      boolean shutDownMIMServer_ = false;
      boolean procNameList_ = false;
      boolean nameTagFound_ = false;
      Vector nameList_ = new Vector();

      public MIMServerDocHandler()
      {
      super();
      }

      public void startElement(String uri_in, String localName_in,
      String qName_in, Attributes attributes_in)
      throws SAXException
      {
      if (qName_in.equals("Name") && procNameList_)
      {
      nameTagFound_ = true;
      return;
      }
      else if (msgBeingProcessed_ == GET_CLASS_DEF_LIST_REQUEST)
      {
      if (qName_in.equals(GET_CLASS_DEF_IGN_CLASSLIST) ||
      qName_in.equals(GET_CLASS_DEF_IGN_CLASS))
      {
      return;
      }
      }

      if (qName_in.equals(GET_CLASS_DEF_LIST_REQUEST))
      {
      msgBeingProcessed_ = GET_CLASS_DEF_LIST_REQUEST;
      procNameList_ = true;
      }
      }

      public void characters(char[] ch_in,
      int start_in,
      int len_in)
      throws SAXException
      {
      if (procNameList_ && nameTagFound_)
      {
      nameList_.add(new String(ch_in, start_in, len_in));
      }
      }

      public void endElement(String uri_in,
      String localName_in,
      String rawName_in)
      throws SAXException
      {
      if (rawName_in.equals("Name") && procNameList_)
      {
      nameTagFound_ = false;
      }
      else if (rawName_in.equals(GET_CLASS_DEF_LIST_REQUEST) &&
      msgBeingProcessed_.equals(GET_CLASS_DEF_LIST_REQUEST))
      {
      for (int i = 0; i < nameList_.size(); i++)
      {
      System.out.println("NameList element[" + i + "] " + nameList_.elementAt(i));
      }
      procNameList_ = false;
      }
      }
      }

      void dissectRequest(String request_in)
      {
      try
      {
      SAXParserFactory saxFactory = SAXParserFactory.newInstance();
      SAXParser parser = saxFactory.newSAXParser();
      StringReader myReader = new StringReader(request_in);
      InputSource inDoc = new InputSource(myReader);
      MIMServerDocHandler mimSAXDocHandler = new MIMServerDocHandler();
      parser.parse(inDoc, mimSAXDocHandler);
      }
      catch (ParserConfigurationException e)
      {
      e.printStackTrace();
      }
      catch (SAXException e)
      {
      e.printStackTrace();
      }
      catch (IOException e)
      {
      e.printStackTrace();
      }
      }

      TestSAX()
      {
      String request = "<GetClassDefsReq><ClassList><Class><Name>ThisIsAReallyBigAndLongClassNameForCurtis</Name></Class></ClassList></GetClassDefsReq>";
      // String request = "<GetClassDefsReq><ClassList><Name>ThisIsAReallyBigAndLongClassNameForCurtis</Name></ClassList></GetClassDefsReq>";
      // String request = "<GetClassDefsReq><ClassList><Class><Name>ThisIsAReallyBigAndLongClassNameForCurtis</Name></Class></ClassList></GetClassDefsReq>";
      // String request = "<GetClassDefsReq><Name>ThisIsAReallyBigAndLongClassNameForCurtis</Name></GetClassDefsReq>";

      dissectRequest(request);
      }

      public static void main(String[] args)
      {

      new TestSAX();
      }
      }

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

            nbajajsunw Neeraj Bajaj (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: