JCR Session.itemExists or nodeExists returns pathnotfound exception instead of true or false

vikramca06

30-01-2019

Hi All,

I am trying to check if a node exist under a path and set some property. but when i try to check a path through session it returns PathNotFoundException instead of true/false.

if(!destSession.nodeExists(dRootPath)) / if(!destSession.itemExists(dRootPath))

is there any other way?

Regards,

Vikram.

Accepted Solutions (1)

Accepted Solutions (1)

Jörg_Hoh

Employee

31-01-2019

According to the stacktrace you get the exception in the "session.getNode()" API call, not in "session.nodeExists()". Thus it's perfectly valid.

Answers (7)

Answers (7)

vikramca06

30-01-2019

Hi All,

please find the sample code (using admin session) and exception below.

@smacdonald2008

to use hasNode() from Node API we need to have the root node. i am trying to check the root node with session and then get it.

if(!destSession.nodeExists(dFolderPath)) {

log.info("Node not found. creating : " + dFolderPath);

Node rootFolderNode = destSession.getNode(dParentPath);

}else{

log.info("Folder Exist : " + dFolderPath);

}

Exception:

javax.jcr.PathNotFoundException: /content/dam/geometrixx/migration/snowboarding

at org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntryImpl.getDeepNodeEntry(NodeEntryImpl.java:395) ~[jackrabbit-jcr2spi-2.10.0.jar:na]

at org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyManagerImpl.getNodeEntry(HierarchyManagerImpl.java:137) ~[jackrabbit-jcr2spi-2.10.0.jar:na]

at org.apache.jackrabbit.jcr2spi.ItemManagerImpl.getNode(ItemManagerImpl.java:168) ~[jackrabbit-jcr2spi-2.10.0.jar:na]

at org.apache.jackrabbit.jcr2spi.SessionImpl.getNode(SessionImpl.java:513) ~[jackrabbit-jcr2spi-2.10.0.jar:na]

vikramca06

30-01-2019

i am using service user with admin rights. for now the node is not exist, in future it might be. so i want to check if the node exist or not then set property.

As per Session (Content Repository for Java Technology API Version 2.0) it should return true/false

Regards,

Vikram