[MAGNOLIA-6426] PropertyUtil.setProperty fails when passing an integer value Created: 23/Oct/15  Updated: 09/Feb/17  Resolved: 16/Jun/16

Status: Closed
Project: Magnolia
Component/s: core
Affects Version/s: 5.4.5, 5.4.7
Fix Version/s: 5.4.8, 5.5

Type: Bug Priority: Neutral
Reporter: Federico Grilli Assignee: Hieu Nguyen Duc
Resolution: Fixed Votes: 0
Labels: support
Remaining Estimate: 3h
Time Spent: 3d 3h
Original Estimate: 3d

Issue Links:
relation
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
Date of First Response:
Sprint: Saigon 48
Story Points: 3

 Description   

Even though JCR's Node API doesn't explicitly allow setting an Integer as a node property (Long is accepted), I think our API could be more lenient and accept an integer value instead of failing as happens to the following code

info.magnolia.jcr.util.PropertyUtil.setProperty(node, "someProperty", 123)

will fail with

java.lang.IllegalArgumentException: Cannot set property to a value of type class java.lang.Integer
at info.magnolia.jcr.util.PropertyUtil.setProperty(PropertyUtil.java:132)

A simple

else if (propertyValue instanceof Integer) {
            node.setProperty(propertyName, ((Integer) propertyValue).intValue());
           }

should do.


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