dev@fi.java.net

setFeature Bug?

From: Alan Hudson <giles_at_oz.net>
Date: Mon, 02 Jan 2006 13:03:05 -0800

I'm running from a bit older CVS, but I think this code is still the same.
 
 public void setFeature(String name, boolean value)
    throws SAXNotRecognizedException, SAXNotSupportedException {
        if (name.equals(Features.NAMESPACES_FEATURE)
        && value == false) {
            throw new SAXNotSupportedException(name + ":" + value);
        } else if (name.equals(Features.NAMESPACE_PREFIXES_FEATURE)) {
            _namespacePrefixesFeature = value;
        } else if (name.equals(Features.STRING_INTERNING_FEATURE) ||
                name.equals(FastInfosetReader.STRING_INTERNING_PROPERTY)) {
            setStringInterning(value);
        } else {
            throw new SAXNotRecognizedException(
                    "Feature not supported: " + name);
        }
    }

If someone calls setFeature(Features.NAMESPACES_FEATURE, with a true
value, they will get a SAXNotRecognizedException.

I think the logic is wrong, as its specifically looking for someone
turning it off.

I'd suggest changing it to:

 public void setFeature(String name, boolean value)
    throws SAXNotRecognizedException, SAXNotSupportedException {
        if (name.equals(Features.NAMESPACES_FEATURE)
        && value == true) {
            // ignore as default
        } else if (name.equals(Features.NAMESPACE_PREFIXES_FEATURE)) {
            _namespacePrefixesFeature = value;
        } else if (name.equals(Features.STRING_INTERNING_FEATURE) ||
                name.equals(FastInfosetReader.STRING_INTERNING_PROPERTY)) {
            setStringInterning(value);
        } else {
            throw new SAXNotRecognizedException(
                    "Feature not supported: " + name);
        }
    }