[MAGNOLIA-8636] PropertyUtil: null list value always converted to list of empty Strings, no matter of the property type Created: 14/Nov/22  Updated: 07/Mar/23

Status: Open
Project: Magnolia
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: Roman Kovařík Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
dependency
is depended upon by MGNLUI-7624 New multiValueField doesn't support n... Open
relation
is related to MGNLUI-7601 Fields (except for the textField) ins... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Epic Link: FieldsMaintenance

 Description   

Steps to reproduce

PropertyUtil.setProperty(node, name, Arrays.asList(Calendar.getInstance().getTime(), null));

Expected results

assertThat(node, hasProperty("multiValue", new Object[]{null, date})); 

passes

Actual results

The assertion fails.

Workaround

Create the value manually like this:

            var valueFactory = node.getSession().getValueFactory();
            node.setProperty(name, ((List<?>) value).stream()
                            .map(Exceptions.wrap().function(o -> o == null ? null : 
             PropertyUtil.createValue(o, valueFactory)))
                    .toArray(Value[]::new)
            );

Development notes

  1. PropertUtils points to https://git.magnolia-cms.com/projects/PLATFORM/repos/main.pub/browse/magnolia-core/src/main/java/info/magnolia/jcr/util/PropertyUtil.java#140
  2. And that to https://git.magnolia-cms.com/projects/PLATFORM/repos/main.pub/browse/magnolia-core/src/main/java/info/magnolia/jcr/util/PropertyUtil.java#347 Here one would expect to not fallback to empty String but just return null as JCR Value
  3. When this is fixed, assertion fails on NPE in PropertyUtil.getValue which might be fixed as well as part of this ticket

Generated at Mon Feb 12 04:34:27 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.