changeset 120:94f63e065244

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
author joehw
date Tue, 27 Oct 2015 04:44:49 +0000
parents 6e513b74e14d
children 6c2627e1bef3
files drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java
diffstat 2 files changed, 15 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java	Tue Oct 27 04:19:21 2015 +0000
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java	Tue Oct 27 04:44:49 2015 +0000
@@ -288,12 +288,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
@@ -1868,7 +1869,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/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java	Tue Oct 27 04:19:21 2015 +0000
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java	Tue Oct 27 04:44:49 2015 +0000
@@ -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();
@@ -646,7 +646,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()) {
@@ -671,7 +671,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);
@@ -679,7 +679,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
@@ -934,6 +934,10 @@
                     }
 
                     case SCANNER_STATE_DOCTYPE: {
+                        if (fDisallowDoctype) {
+                            reportFatalError("DoctypeNotAllowed", null);
+                        }
+
                         
                         if (fSeenDoctypeDecl) {
                             reportFatalError("AlreadySeenDoctype", null);
@@ -942,7 +946,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;
@@ -952,8 +956,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){
@@ -968,7 +970,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);
@@ -985,7 +987,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);
@@ -1133,7 +1135,7 @@
                                 }
                                 fMarkupDepth--;
                                 
-                                if (fDisallowDoctype) {
+                                if (!fSupportDTD) {
                                     //simply reset the entity store without having to mess around 
                                     //with the DTD Scanner code
                                     fEntityStore = fEntityManager.getEntityStore();