java.lang.IllegalArgumentException: Value for key (property name) can't be put into node | Community
Skip to main content
Level 2
January 25, 2018

java.lang.IllegalArgumentException: Value for key (property name) can't be put into node

  • January 25, 2018
  • 5 replies
  • 22889 views

Hi everyone,

                     i am trying to add/update new/existing property with value to asset metadata and when i say resolver.commit(), it results in following exception

java.lang.IllegalArgumentException: Value for key (property name here) can't be put into node: [Ljava.lang.String;@1455d8b2

at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:458)

at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:47)

aused by: javax.jcr.version.VersionException: Cannot set property. Node [path/to/asset/jcr:content/metadata] is checked in.

at org.apache.jackrabbit.oak.jcr.session.NodeImpl$36.checkPreconditions(NodeImpl.java:1404)

at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.prePerform(SessionDelegate.java:615)

at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:205)

at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:112)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1399)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:378)

at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:453)

... 19 common frames omitted

E2: java.lang.IllegalArgumentException: Value for key (some other property)  can't be put into node: update (value)

at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:458)

at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:47)

aused by: javax.jcr.version.VersionException: Cannot set property. Node [path/to/asset/jcr:content/metadata] is checked in.

at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.checkPreconditions(NodeImpl.java:1368)

at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.prePerform(SessionDelegate.java:615)

at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:205)

at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:112)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1363)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:351)

at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:455)

... 21 common frames omitted

When i reprocess the same asset for creating/updating same metadata property, it works well. Please suggest any improvements here.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

5 replies

smacdonald2008
Level 10
January 25, 2018

Please provide the exact steps you are performing so community can try and reduplicate this issue.

Level 2
January 25, 2018

Thanks for letting me know, smacdonald2008

Here is the code snippet for the same,

String customValue = "update";

Resource assetRsc = resolver.getResource("path/to/asset/metadata");

if(assetRsc !=null) {

    ModifiableValueMap properties = assetRsc.adaptTo(ModifiableValueMap.class);

     properties.put("custom_property", customValue );

     // some more properties to be set here

     saveToRepo(resolver);

}

private void saveToRepo(ResourceResolver resolver){

try {

resolver.commit();

} catch (PersistenceException e) {

logger.error("Exception while saving changes :", e);

}

}

I hope this helps understanding. Please let me know, if any other information is required.

rmahendra
Adobe Employee
Adobe Employee
January 26, 2018

The code looks good. What is the exact value you are trying to put?

Level 2
January 26, 2018

Hi rmahendr

                          the values(create/update/delete) i use are of string type. The second property takes string[] type values.

Thanks & Regards,

Radhakrishna.

BrijeshYadav
Level 5
January 26, 2018

Try Asset API. Asset ("The Adobe AEM Quickstart and Web Application.")

Asset is created by AssetManager and can be retrieved either via AssetManager or by adapting a asset Resource to an Asset.

     eg:

     // to create an asset

     AssetManager assetManager = resolver.adaptTo(AssetManager.class);

     Asset newAsset = assetManager.createAsset("/path/to/asset/document.pdf");

     // to get an existing asset

     Asset asset = assetManager.getAsset("/path/to/asset/document.pdf");

     // to get asset by adapting

     Asset asset = resource.adaptTo(Asset.class);

Asset properties can be retrieved or set by adapting it to a ValueMap.

     eg:

     // to get Asset properties value map

     ValueMap map = asset.adaptTo(ValueMap.class);

/Brijesh Yadav

Level 2
January 26, 2018

Hi Yadav Brijesh,

                            thanks for your suggestion. I would look to understand your suggestion using Asset API. What advantage are we going to get when compared to Resource. Can you please help putting your view here and how that helps this problem to be solved?

Thanks & Regards,

Radhakrishna.

smacdonald2008
Level 10
January 26, 2018

When working with AEM - if there is a corresponding API - like Asset Manager API, Tag Manager API, etc, you should ways use these strongly types APIs when programmatically working with AEM.

Here is URL to the Javadocs - "The CQ5 Quickstart and Web Application."

** MAY MAKE A GOOD Ask the AEM Community Session**

joerghoh
Adobe Employee
Adobe Employee
January 30, 2018

Have you seen that the exception contains this line:

> javax.jcr.version.VersionException: Cannot set property. Node [path/to/asset/jcr:content/metadata] is checked in.

You need to check out that node first to continue to save() properties. Not sure why it has been checked-in without being checked-out.

Jörg

Level 2
January 31, 2018

Hi Jörg Hoh,

                        yes, i could see version exception as follows,

Caused by: javax.jcr.version.VersionException: Cannot set property. Node [/content/dam/path/to/asset/jcr:content/metadata] is checked in.

at org.apache.jackrabbit.oak.jcr.session.NodeImpl$36.checkPreconditions(NodeImpl.java:1404)

at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.prePerform(SessionDelegate.java:615)

at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:205)

at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:112)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1399)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:378)

at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:453)

I am wondering who is checking in this asset. Is there any way to figure out?

Thanks & Regards,

Radhakrishna.

joerghoh
Adobe Employee
Adobe Employee
January 31, 2018

Hi,

that's not immediately visible. I remember cases where this happened for pages on "pagemanager.createVersion()", could be for assets the same. In general, node.checkin() and node.checkout() are part of the versioning. Maybe this can help you to track down suspect log entries.

Jörg

sriramking
January 9, 2019

This happens when the map already has key with same name. to update you have to remove it and then put new values like map.remove(propertyname); map.put(propertyname,value);resourceResolver.commit();

Hope it helps.