[ 
https://issues.apache.org/jira/browse/JXPATH-80?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12490148
 ] 

Nico Max commented on JXPATH-80:
--------------------------------

The Javadoc of getLength() states, that it returns "1" if the property does not 
contain a collection, which is the case for a NULL-property value; so I thought 
to be safe.

Lets wrap up the XPath v1.0 spec. 

- (chap. 1):  "An expression is evaluated to yield an object, which has one of 
the following four basic types:

node-set (an unordered collection of nodes without duplicates) 
boolean (true or false) 
number (a floating-point number) 
string (a sequence of UCS characters)."

- (chap 3.4): " If one object to be compared is a node-set and the other is a 
boolean, then the comparison will be true if and only if the result of 
performing the comparison on the boolean and on the result of converting the 
node-set to a boolean using the boolean function is true."

- (chap. 4.3): The boolean() function treats nodesets like this:

             "a node-set is true if and only if it is non-empty"

So the location path in the expression "bean/value1 = false()" (from the 
attached test) is supposed to result in an empty node set, as 
"java.lang.Object" is not one of the other basic Xpath types. And an empty node 
set is being treated as "false" in an equality operation.

Yes, the test fails with the patch, but it fails without the patch too after 
applying the following additions:

- Give the TestNull-class a getter like this:

    public String getNothing2() {
        return null;
    }

- Add the following assert to MixedModelTest.testNull():

        assertXPathValueIterator(
                context,
                "$testnull/nothing2",
                Collections.EMPTY_LIST);

This gives the same result.

> boolean conversion of javabean getter values returning NULL fails
> -----------------------------------------------------------------
>
>                 Key: JXPATH-80
>                 URL: https://issues.apache.org/jira/browse/JXPATH-80
>             Project: Commons JXPath
>          Issue Type: Bug
>    Affects Versions: 1.2 Final
>         Environment: java.runtime.name=Java(TM) SE Runtime Environment
> java.runtime.version=1.6.0-b105
> java.specification.name=Java Platform API Specification
> java.specification.vendor=Sun Microsystems Inc.
> java.vm.info=mixed mode
> java.vm.name=Java HotSpot(TM) Client VM
>            Reporter: Nico Max
>            Priority: Minor
>         Attachments: patch.patch, patch.patch, test.java
>
>
> According to the JXPath User Guide a Javabean Getter returning NULL, 
> regadless of the type, will be converted bo Boolean FALSE. But trying to 
> build a boolean expression from this fails as the attached testcase shows.
> It seems that the type the bean getter returns matters, as a NULL String for 
> example works as expected.

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to