7157610: NullPointerException occurs when parsing XML doc
Summary: recovers what was the original disallow-doctype-decl, reporting error when disallow-doctype-decl is true, and change everything else that was added for SupportDTD to be governed by a new flag 'fSupportDTD'.
Reviewed-by: lancea
--- a/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java Fri Jun 08 11:28:29 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java Mon Jun 11 15:47:01 2012 -0700
@@ -286,12 +286,13 @@
//STAX related properties
//defaultValues.
+ protected boolean fSupportDTD = true;
protected boolean fReplaceEntityReferences = true;
protected boolean fSupportExternalEntities = false;
protected boolean fReportCdataEvent = false ;
protected boolean fIsCoalesce = false ;
protected String fDeclaredEncoding = null;
- /** Disallow doctype declaration. */
+ /** Xerces Feature: Disallow doctype declaration. */
protected boolean fDisallowDoctype = false;
// drivers
@@ -1847,7 +1848,7 @@
// start general entity
if (!fEntityStore.isDeclaredEntity(name)) {
//SUPPORT_DTD=false && ReplaceEntityReferences should throw exception
- if (fDisallowDoctype && fReplaceEntityReferences) {
+ if (!fSupportDTD && fReplaceEntityReferences) {
reportFatalError("EntityNotDeclared", new Object[]{name});
return;
}
--- a/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java Fri Jun 08 11:28:29 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java Mon Jun 11 15:47:01 2012 -0700
@@ -278,7 +278,7 @@
fDoctypeSystemId = null;
fSeenDoctypeDecl = false;
fNamespaceContext.reset();
- fDisallowDoctype = !((Boolean)propertyManager.getProperty(XMLInputFactory.SUPPORT_DTD)).booleanValue();
+ fSupportDTD = ((Boolean)propertyManager.getProperty(XMLInputFactory.SUPPORT_DTD)).booleanValue();
// xerces features
fLoadExternalDTD = !((Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD)).booleanValue();
@@ -628,7 +628,7 @@
// scanning methods
/** Scans a doctype declaration. */
- protected boolean scanDoctypeDecl(boolean ignore) throws IOException, XNIException {
+ protected boolean scanDoctypeDecl(boolean supportDTD) throws IOException, XNIException {
// spaces
if (!fEntityScanner.skipSpaces()) {
@@ -653,7 +653,7 @@
fHasExternalDTD = fDoctypeSystemId != null;
// Attempt to locate an external subset with an external subset resolver.
- if (!ignore && !fHasExternalDTD && fExternalSubsetResolver != null) {
+ if (supportDTD && !fHasExternalDTD && fExternalSubsetResolver != null) {
fDTDDescription.setValues(null, null, fEntityManager.getCurrentResourceIdentifier().getExpandedSystemId(), null);
fDTDDescription.setRootName(fDoctypeName);
fExternalSubsetSource = fExternalSubsetResolver.getExternalSubset(fDTDDescription);
@@ -661,7 +661,7 @@
}
// call handler
- if (!ignore && fDocumentHandler != null) {
+ if (supportDTD && fDocumentHandler != null) {
// NOTE: I don't like calling the doctypeDecl callback until
// end of the *full* doctype line (including internal
// subset) is parsed correctly but SAX2 requires that
@@ -916,6 +916,10 @@
}
case SCANNER_STATE_DOCTYPE: {
+ if (fDisallowDoctype) {
+ reportFatalError("DoctypeNotAllowed", null);
+ }
+
if (fSeenDoctypeDecl) {
reportFatalError("AlreadySeenDoctype", null);
@@ -924,7 +928,7 @@
// scanDoctypeDecl() sends XNI doctypeDecl event that
// in SAX is converted to startDTD() event.
- if (scanDoctypeDecl(fDisallowDoctype)) {
+ if (scanDoctypeDecl(fSupportDTD)) {
//allow parsing of entity decls to continue in order to stay well-formed
setScannerState(SCANNER_STATE_DTD_INTERNAL_DECLS);
fSeenInternalSubset = true;
@@ -934,8 +938,6 @@
setDriver(fContentDriver);
//always return DTD event, the event however, will not contain any entities
return fDTDDriver.next();
- // If no DTD support, ignore and continue parsing
- //return fDisallowDoctype ? next() : dtdEvent;
}
if(fSeenDoctypeDecl){
@@ -950,7 +952,7 @@
if (fDoctypeSystemId != null) {
if (((fValidation || fLoadExternalDTD)
&& (fValidationManager == null || !fValidationManager.isCachedDTD()))) {
- if (!fDisallowDoctype)
+ if (fSupportDTD)
setScannerState(SCANNER_STATE_DTD_EXTERNAL);
else
setScannerState(SCANNER_STATE_PROLOG);
@@ -967,7 +969,7 @@
// This handles the case of a DOCTYPE that had neither an internal subset or an external subset.
fDTDScanner.setInputSource(fExternalSubsetSource);
fExternalSubsetSource = null;
- if (!fDisallowDoctype)
+ if (fSupportDTD)
setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS);
else
setScannerState(SCANNER_STATE_PROLOG);
@@ -1113,7 +1115,7 @@
}
fMarkupDepth--;
- if (fDisallowDoctype) {
+ if (!fSupportDTD) {
//simply reset the entity store without having to mess around
//with the DTD Scanner code
fEntityStore = fEntityManager.getEntityStore();