An incomplete fix for the NPE bugs in AbstractDOMParser.java
------------------------------------------------------------
Key: XERCESJ-1555
URL: https://issues.apache.org/jira/browse/XERCESJ-1555
Project: Xerces2-J
Issue Type: Bug
Components: Other
Reporter: Guangtai Liang
Priority: Critical
The fix revision 318356 was aimed to remove an NPE bug on the "this.locator" in
the method "startDocument" of the file
"/xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java" , but
it is incomplete.
Since the "this.locator" is a class field and also could be null during the
run-time execution, it should also be null-checked before being dereferenced in
other methods.
The buggy code locations the same fix needs to be applied at are as bellows:
Lines 626 and 673 of the method "startDocument":
public void startDocument(XMLLocator locator, String encoding, Augmentations
augs)
throws XNIException {
fInDocument = true;
if (!fDeferNodeExpansion) {
if (fDocumentClassName.equals(DEFAULT_DOCUMENT_CLASS_NAME)) {
fDocument = new DocumentImpl();
fDocumentImpl = (CoreDocumentImpl)fDocument;
// REVISIT: when DOM Level 3 is REC rely on Document.support
// instead of specific class
// set DOM error checking off
fDocumentImpl.setStrictErrorChecking(false);
// set actual encoding
fDocumentImpl.setActualEncoding(encoding);
// set documentURI
fDocumentImpl.setDocumentURI(locator.getExpandedSystemId());
}
else {
// use specified document class
try {
Class documentClass = Class.forName(fDocumentClassName);
fDocument = (Document)documentClass.newInstance();
// if subclass of our own class that's cool too
Class defaultDocClass =
Class.forName(CORE_DOCUMENT_CLASS_NAME);
if (defaultDocClass.isAssignableFrom(documentClass)) {
fDocumentImpl = (CoreDocumentImpl)fDocument;
// REVISIT: when DOM Level 3 is REC rely on
// Document.support instead of specific class
// set DOM error checking off
fDocumentImpl.setStrictErrorChecking(false);
// set actual encoding
fDocumentImpl.setActualEncoding(encoding);
// set documentURI
if (locator != null) {
fDocumentImpl.setDocumentURI(locator.getExpandedSystemId());
}
}
}
catch (ClassNotFoundException e) {
// won't happen we already checked that earlier
}
catch (Exception e) {
// REVISIT: Localize this message.
throw new RuntimeException(
"Failed to create document object of class: "
+ fDocumentClassName);
}
}
fCurrentNode = fDocument;
}
else {
fDeferredDocumentImpl = new DeferredDocumentImpl(fNamespaceAware);
fDocument = fDeferredDocumentImpl;
fDocumentIndex = fDeferredDocumentImpl.createDeferredDocument();
// REVISIT: when DOM Level 3 is REC rely on
// Document.support instead of specific class
fDeferredDocumentImpl.setStrictErrorChecking(false);
// set actual encoding
fDeferredDocumentImpl.setActualEncoding(encoding);
// set documentURI
fDeferredDocumentImpl.setDocumentURI(locator.getExpandedSystemId());
fCurrentNodeIndex = fDocumentIndex;
}
} // startDocument(String,String)
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]