#319 Element.setNamespacePrefix(String) throws IAE?

2.2 (final)
closed-fixed
5
2010-02-06
2009-07-04
No

The setNamespacePrefix(String) method in the class org.xins.common.xml.Element documents that it throws an IllegalArgumentException. However, looking at the source code, it seems that this is not correct.

This is the current code:

/**
* Sets the namespace prefix.
*
* @param namespacePrefix
* the namespace prefix of this element, can be <code>null</code>.
* If the value if <code>null</code> or an empty string, the element is
* consider to have no namespace prefix.
*
* @throws IllegalArgumentException
* if <code>namespacePrefix == null</code>.
*
* @since XINS 2.1
*/
public void setNamespacePrefix(String namespacePrefix) throws IllegalArgumentException {
if (namespacePrefix != null && namespacePrefix.length() == 0) {
_namespacePrefix = null;
} else {
_namespacePrefix = namespacePrefix;
}
}

Proposed changed code:

/**
* Sets the namespace prefix.
*
* @param namespacePrefix
* the namespace prefix of this element;
* if it is <code>null</code> or an empty string, then the element is
* considered to have no namespace prefix.
*
* @since XINS 2.1
*/
public void setNamespacePrefix(String namespacePrefix) {
_namespacePrefix = (namespacePrefix == null || namespacePrefix.length() == 0)
? = null
: = namespacePrefix;

// Keep the namespace URI consistent
if (_namespacePrefix == null) {
_namespaceURI = null;
}
}

Something similar applies to the setNamespaceURI(String) method.

Even with this improvement, I wonder if these two methods should not be combined. Otherwise an Element could still have a namespace prefix but no namespace URI, or vice versa. Perhaps we should just have:

setNamespace(String prefix, Sting uri) { ... }
setNamespace(String uri) { ... } // automatically choses a prefix

Discussion

  • Ernst de Haan

    Ernst de Haan - 2009-07-04

    Patch (also containing a lot more changes!)

     
  • Ernst de Haan

    Ernst de Haan - 2009-07-04

    Note that that patch file (a unified diff) also contains many more changes. You may not want to add all changes, although I consider the documentation changes improvements over the current text.

     
  • Anthony Goubard

    Anthony Goubard - 2010-02-06

    Fixed, will be in 2.3-alpha3.

     
  • Anthony Goubard

    Anthony Goubard - 2010-02-06
    • assigned_to: nobody --> agoubard
    • status: open --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks