JDK-6440324 : StAX implementation not spec compliant - breaks RI compliant apps
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.stream
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2006-06-19
  • Updated: 2016-09-22
  • Resolved: 2006-07-17
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
6 b92Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0-beta2"
Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86)
Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Linux wh58-307 2.6.16.18 #1 SMP PREEMPT Tue May 30 20:43:33 MEST 2006 i686 athlon i386 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
StAX implementation validates input even if the XMLInputFactory has been instructed to not validate the content, which is read. This is not spec compliant and breaks existing applications, which work without any problems using Bea/Codehaus StAX RI implementation.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Read an XML file, whoms DOCTYPE system id points to a none-existing dtd file and set the XMLInputFactory.IS_VALIDATING to false.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
One can parse the file without any problems.
ACTUAL -
javax.xml.stream.XMLStreamException: ParseError at [row,col]:[2,100]
Message: /dev/null/action.dtd (No such file or directory)
	at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:540)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
String root = "root";
		XMLInputFactory xif = XMLInputFactory.newInstance();
		xif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
		xif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES,
			Boolean.TRUE);
		xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE,
			Boolean.valueOf(namespaceAware));
		xif.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
//		xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,
//			Boolean.FALSE);
		try {
			XMLStreamReader reader = xif.createXMLStreamReader(src);
			while(reader.hasNext()) {
				int e = reader.next();
				if (e == XMLStreamConstants.START_ELEMENT) {
					if (root == null || reader.getLocalName().equals(root)) {
						return reader;
					}
					fastForwardToEndOfElement(reader);
				}
			}
		} catch (XMLStreamException e) {
			if (e.getNestedException() != null) {
				log.warn(e.getNestedException().getLocalizedMessage());
			} else {
				log.warn(e.getLocalizedMessage());
			}
			if (log.isDebugEnabled()) {
				log.debug("getReader", e);
			}
		} catch (Exception e) {
			log.warn(e.getLocalizedMessage());
			if (log.isDebugEnabled()) {
				log.debug("getReader", e);
			}
		}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Avoid using the SUN StAX implementation and use the RI instead.

Comments
EVALUATION note that the XML specification does allow for the reading of an external DTD subset for entity resolution etc. regardless of validation. the fix will recover from a failed external DTD subset resolution if non-validating.
11-07-2006

EVALUATION behavior is reproducible so CR is being accepted.
20-06-2006