Repository navigation
JXPATH-205: A null collection or array property has no elements - #296
Open
sharanggupta wants to merge 1 commit into
Open
sharanggupta wants to merge 1 commit into
sharanggupta wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes JXPATH-205.
What
Since 1.4.0,
size(bar/words)returns 1 instead of 0 whenwordsis a nullList. The same happens tocount(words), and to a null array property such ascount(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/atrue whenmap/bis 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 aCollection(ValueUtils.getCollectionHint(...) == 1) and its value is null. A null property of any other type, includingObjectand map entries, is still a single node, so the JXPATH-151 behaviour andMixedModelTest.testNullare unchanged.This affects every use of the length, not only
count()andsize():iterate()andselectNodes()on such a property yield no node again instead of one null node, as in 1.3.Tests
New
JXPath205Test, next toJXPath151Test:count(letters)for a nullString[]count(words)for a nullListsize(words)for a nullListcount(nothing)for a nullObjectThe first three fail on master and pass with this change. Verified locally with the default
mvngoal 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 inJDOMModelTest.Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.