镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

JXPATH-205: A null collection or array property has no elements - #296

Open
sharanggupta wants to merge 1 commit into
apache:masterfrom
sharanggupta:JXPATH-205-size-of-null-collection
Open

sharanggupta wants to merge 1 commit into
apache:masterfrom
sharanggupta:JXPATH-205-size-of-null-collection

Conversation

@sharanggupta

@sharanggupta sharanggupta commented Oct 15, 2026 •

Copy link
Copy Markdown

Fixes 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 (99a2078), 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.

This affects every use of the length, not only count() and size(): iterate() and selectNodes() on such a property yield no node again instead of one null node, as in 1.3.

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:

  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance if you use Artificial Intelligence (AI).
  • 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.
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • 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.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • 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.

Since JXPATH-151 a property whose value is null counts as one node, so
that, for example, map/b != map/a is true when map/b is null. This also
applied to bean properties declared as an array or a collection, which
in JXPath 1.3 had no elements when null: count(words) and size(words)
returned 1 for a null List instead of 0.

Return a length of 0 for a null bean property whose type is an array or
a Collection. A null property of any other type is still a single node.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant