Bug 10088 - TraverseSchema throws NPE when InputSource has null systemId
Summary: TraverseSchema throws NPE when InputSource has null systemId
Status: NEW
Alias: None
Product: Xerces-J
Classification: Unclassified
Component: Schema-Structures (show other bugs)
Version: 1.4.4
Hardware: All All
: P3 minor
Target Milestone: ---
Assignee: Xerces-J Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-06-20 19:59 UTC by Clyde Gerber
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Clyde Gerber 2002-06-20 19:59:35 UTC
TraverseSchema will throw a NPE in its openRedefinedSchema method if the 
EntityResolver returns an InputSource from its resolveEntity method which has a 
null systemId.

The source code that is causing the problem is:

    private void openRedefinedSchema(Element redefineDecl, SchemaInfo store) 
throws Exception {
        Attr locationAttr = redefineDecl.getAttributeNode
(SchemaSymbols.ATT_SCHEMALOCATION);
        if (locationAttr == null) {
            // REVISIT: Localize
            fRedefineSucceeded = false;
            reportGenericSchemaError("a schemaLocation attribute must be 
specified on a <redefine> element");
            return;
        }
        String location = locationAttr.getValue();

        // expand it before passing it to the parser
        InputSource source = null;
        if (fEntityResolver != null) {
            source = fEntityResolver.resolveEntity("", location);
        }

        if (source == null) {
            location = expandSystemId(location, fCurrentSchemaURL);
            source = new InputSource(location);
        }
        // Make sure we don't redefine the same schema twice; it's allowed
        // but the specs encourage us to avoid it.
        // algorithm:  string is pubId+sysId or if both null then filename
        String pubId = "";
        String sysId = "";
        if (source.getPublicId () != null)
            pubId = source.getPublicId ();
        if (source.getSystemId () != null)
            sysId = source.getSystemId ();

        if(pubId.length() != 0 || sysId.length() != 0)
            location += pubId+sysId;

        // make sure we're not redefining ourselves!
        if(source.getSystemId().equals(fCurrentSchemaURL)) { // NPE if 
source.getSystemId() == null!

Possible solutions are to use the sysId variable which was previously set, or 
to require that the redefined schema's systemId be non-null and throw an 
exception with the appropriate message, or to require that either the current 
schema's systemId or the redefined schema's systemId be non-null and throw the 
appropriate exception.