JDK-6716309 : SAXParser does not parse correctly
  • Type: Bug
  • Component: xml
  • Sub-Component: org.xml.sax
  • Affected Version: 6u5
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows
  • CPU: x86
  • Submitted: 2008-06-18
  • Updated: 2012-04-25
  • Resolved: 2008-06-18
Related Reports
Duplicate :  
Description
The following sample code and attached XML demonstrates the issue SAXParser does not parse an XML file correctly.

// Test program to demonstrate a data corruption error in SAXParser.
//
// 2008-06-18 Christian d'Heureuse, ###@###.###, www.source-code.biz
//
// Environments tested in which the error occurs:
//  1.6.0_10-beta-b25 Windows XP SP2        (includes Xerces 2.6.2)
//  1.6.0_06-b02      Windows XP SP2        (includes Xerces 2.6.2)
//  1.6.0_05-b13      Windows XP SP2        (includes Xerces 2.6.2)
//
// Environments tested in which the error does not occur:
//  1.6.0_10-beta-b25 Windows XP SP2  with Xerces snapshot 2008-06-15 (file xml-parser-gump-15062008.jar)
//  1.6.0_10-beta-b25 Windows XP SP2  with Xerces 2.9.1
//  1.6.0_10-beta-b25 Windows XP SP2  with Xerces 2.8.1
//  1.5.0_10-b03      Linux                 (includes Xerces 2.6.2)
//
// (Note that the Xerces JAR file must be copied into the lib/endorsed
// directory, in order to override the Xerces classes of the Java library.
// It's not sufficient to include the JAR file in the classpath.)

import java.io.File;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.helpers.DefaultHandler;

public class SaxParserError extends DefaultHandler {

private static final String inputFileName = "SaxParserError.xml";
private static final String testPattern   = "column-data";

public static void main (String args[]) throws Exception {
   SAXParser saxParser;
   SAXParserFactory factory = SAXParserFactory.newInstance();
   factory.setValidating(false);
   saxParser = factory.newSAXParser();
   saxParser.parse(new File(inputFileName), new SaxParserError());
   System.out.println ("OK, no error detected."); }

public void characters(char buf[], int offset, int len) {
   String s = new String(buf, offset, len);
   if (s.contains(testPattern)) {
      System.out.println ("Data corruption error detected.");
      System.exit (9); }}

} // end class SaxParserError