jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • jaxen
  • JAXEN-5

o.j.dom.DocumentNavigator methods do not return null where expected

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 1.0, 1.1
  • Fix Version/s: 1.2
  • Component/s: dom
  • Labels:
    None

Description

Some of the methods in the org.jaxen.dom.DocumentNavigator class declare that they will return null if the argument is not of the expected node type but, in fact, they do not check the node type at all. The affected methods are:

getElementNamespaceUri (Object object)
getElementName (Object object)
getElementQName (Object object)
getAttributeNamespaceUri (Object object)
getAttributeName (Object object)
getAttributeQName (Object object)

Additionally, the following methods may throw a ClassCastException for the same reason (they do not check the node type of the argument), and they do not have any javadoc comments to advertise their expected behavior:

getProcessingInstructionTarget(Object obj)
getProcessingInstructionData(Object obj)

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Elliotte Rusty Harold added a comment - 13/Jan/05 10:40 PM

We should evaluate the whole idea of returning null when an unexpected node type is received. In general, I think throwing an exception would be a much better option than returning null.

Show
Elliotte Rusty Harold added a comment - 13/Jan/05 10:40 PM We should evaluate the whole idea of returning null when an unexpected node type is received. In general, I think throwing an exception would be a much better option than returning null.
Hide
Permalink
Brian Ewins added a comment - 14/Jan/05 6:52 AM

I guess its worth pointing out that these methods are never called incorrectly in jaxen: there's always a call to 'isElement()' prior to 'getElementStringValue' for example. (the calls should probably be to getNodeType() in most cases, but thats another issue)

I wouldn't 'fix' these methods as it would involve duplicating the check that needs to be done outside the call anyway. How about changing the documentation so that 'calling getElementStringValue on a non-Element node has an undefined result'?

On your point about nulls: totally agree. There is no null in the xpath datamodel. Null nodesets should be empty Lists, null Strings should be "", everything else follows from the type conversion rules.

Show
Brian Ewins added a comment - 14/Jan/05 6:52 AM I guess its worth pointing out that these methods are never called incorrectly in jaxen: there's always a call to 'isElement()' prior to 'getElementStringValue' for example. (the calls should probably be to getNodeType() in most cases, but thats another issue) I wouldn't 'fix' these methods as it would involve duplicating the check that needs to be done outside the call anyway. How about changing the documentation so that 'calling getElementStringValue on a non-Element node has an undefined result'? On your point about nulls: totally agree. There is no null in the xpath datamodel. Null nodesets should be empty Lists, null Strings should be "", everything else follows from the type conversion rules.
Hide
Permalink
Elliotte Rusty Harold added a comment - 14/Jan/05 7:04 AM

These are public methods so we do need to document what happens when unexpected objects are passed to them. Even if Jaxen never passes the wrong type in, we can't assume all other code will be equally correct.

Show
Elliotte Rusty Harold added a comment - 14/Jan/05 7:04 AM These are public methods so we do need to document what happens when unexpected objects are passed to them. Even if Jaxen never passes the wrong type in, we can't assume all other code will be equally correct.
Hide
Permalink
Brian Ewins added a comment - 14/Jan/05 7:50 AM

I see it differently: the point of the Navigator interface is to specify what jaxen needs from a third party object model. Hence jaxen defines how Navigators should be called. The interface is only public so that it can be implemented by third parties, not called by them. Hence, defining behaviour and adding checks for a calling pattern other than jaxen's would only end up slowing jaxen down.

That being said, adding assertions would be the right way to go, if jaxen required 1.4+ to build.

(just my opinion, I'm a committer not the project lead. Its worth discussing on the list)

Show
Brian Ewins added a comment - 14/Jan/05 7:50 AM I see it differently: the point of the Navigator interface is to specify what jaxen needs from a third party object model. Hence jaxen defines how Navigators should be called. The interface is only public so that it can be implemented by third parties, not called by them. Hence, defining behaviour and adding checks for a calling pattern other than jaxen's would only end up slowing jaxen down. That being said, adding assertions would be the right way to go, if jaxen required 1.4+ to build. (just my opinion, I'm a committer not the project lead. Its worth discussing on the list)
Hide
Permalink
Brian Ewins added a comment - 18/Jan/05 9:03 PM

I've updated the code so that none of the get*Iterator methods return null. This makes the code dealing with them simpler (and faster) as they no longer have to check the return value. There's still nearly 100 unnecessary checks for nulls dealing with these stringvalue methods, I'd like to whittle these down next.

Show
Brian Ewins added a comment - 18/Jan/05 9:03 PM I've updated the code so that none of the get*Iterator methods return null. This makes the code dealing with them simpler (and faster) as they no longer have to check the return value. There's still nearly 100 unnecessary checks for nulls dealing with these stringvalue methods, I'd like to whittle these down next.
Hide
Permalink
Elliotte Rusty Harold added a comment - 26/Apr/08 6:50 PM

Performance wise, and code-wise, I think what should happen is

1. We just make the cast without any check; that is, assume we're being passed the right type.
2. If the type is incorrect, allow the ClasscastException to be thrown.

We could maintain existing behavior if necessary, by catching the ClassCastException and only then returning null.

Show
Elliotte Rusty Harold added a comment - 26/Apr/08 6:50 PM Performance wise, and code-wise, I think what should happen is 1. We just make the cast without any check; that is, assume we're being passed the right type. 2. If the type is incorrect, allow the ClasscastException to be thrown. We could maintain existing behavior if necessary, by catching the ClassCastException and only then returning null.

People

  • Assignee:
    bob mcwhirter
    Reporter:
    Ari Kermaier
Vote (1)
Watch (1)

Dates

  • Created:
    31/Jan/03 1:27 PM
    Updated:
    26/Apr/08 6:50 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.