sharanggupta opened a new pull request, #296:
URL: https://github.com/apache/commons-jxpath/pull/296

   Fixes [JXPATH-205](https://issues.apache.org/jira/browse/JXPATH-205).
   
   **What**
   
   Since 1.4.0, `size(bar/words)` returns 1 instead of 0 when `words` is a null 
`List`. The same happens to `count(words)`, and to a null array property such 
as `count(letters)`: the property is iterated as one node with a null value.
   
   The cause is the JXPATH-151 change (99a20785), released in 1.4.0. To make 
`map/b != map/a` true when `map/b` is null, `PropertyPointer.getLength()` 
returns 1 for a null value. `BeanPropertyPointer.getLength()` delegates to it 
for properties that may be collections, so a null array or collection property 
also became one node, whereas in 1.3 it had no elements.
   
   **How**
   
   `BeanPropertyPointer.getLength()` returns 0 when the property's declared 
type is an array or a `Collection` (`ValueUtils.getCollectionHint(...) == 1`) 
and its value is null. A null property of any other type, including `Object` 
and map entries, is still a single node, so the JXPATH-151 behaviour and 
`MixedModelTest.testNull` are unchanged.
   
   **Tests**
   
   New `JXPath205Test`, next to `JXPath151Test`:
   
   | Expression | Before | After |
   |---|---|---|
   | `count(letters)` for a null `String[]` | 1 | 0 |
   | `count(words)` for a null `List` | 1 | 0 |
   | `size(words)` for a null `List` | 1 | 0 |
   | `count(nothing)` for a null `Object` | 1 | 1 |
   
   The first three fail on master and pass with this change. Verified locally 
with the default `mvn` goal on Java 17 (419 tests, RAT, japicmp, Checkstyle, 
PMD, Javadoc) and the related test classes on Java 8. The single skipped test 
is the existing one in `JDOMModelTest`.
   
   Before you push a pull request, review this list:
   
   - [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
   - [x] Read the [ASF Generative Tooling 
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use 
Artificial Intelligence (AI).
   - [x] I used AI to create any part of, or all of, this pull request. Which 
AI tool was used to create this pull request, and to what extent did it 
contribute? Claude (Anthropic) helped trace the regression and draft the fix 
and the tests; I reviewed all of it, ran the builds and checked that the new 
tests fail without the change.
   - [x] Run a successful build using the default 
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command 
line by itself.
   - [x] Write unit tests that match behavioral changes, where the tests fail 
if the changes to the runtime are not applied. This may not always be possible, 
but it is a best practice.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Each commit in the pull request should have a meaningful subject line 
and body. Note that a maintainer may squash commits during the merge process.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to