Infinite loop in XmlSchemaSerializer. setupNamespaces
-----------------------------------------------------

                 Key: WSCOMMONS-539
                 URL: https://issues.apache.org/jira/browse/WSCOMMONS-539
             Project: WS-Commons
          Issue Type: Bug
          Components: XmlSchema
    Affects Versions: XmlSchema 1.4.6
            Reporter: Brian McDonald
            Priority: Critical


This block of code can cause an infinite loop:

        if (xsdPrefix == null) {
                    //find a prefix to use
                    xsdPrefix = "";
                    if (ctx != null && ctx.getNamespaceURI(xsdPrefix) != null) {
                        xsdPrefix = "xsd";
                     }
                    int count = 0;
                    while (ctx != null && ctx.getNamespaceURI(xsdPrefix) != 
null) {
                        xsdPrefix = "xsd" + ++count;                            
    
                    }
                }

The crux of the problem is that getNamespaceURI will never return null. If the 
namespace uri isn't found it returns XMLConstants.NULL_NS_URI.

This code should help:

        if(xsdPrefix == null) {
            //find a prefix to use
            xsdPrefix = XMLConstants.DEFAULT_NS_PREFIX;
            // Note: NULL_NS_URI is *not* the same as the null reference!
            if (ctx != null && 
!XMLConstants.NULL_NS_URI.equals(ctx.getNamespaceURI(xsdPrefix))) {
                xsdPrefix = "xsd";
            }
            int count = 0;
            while (ctx != null && 
!XMLConstants.NULL_NS_URI.equals(ctx.getNamespaceURI(xsdPrefix))) {
                xsdPrefix = "xsd" + ++count;
            }
            schemaObj.schema_ns_prefix = xsdPrefix;
        }        


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to