JCR Session.itemExists or nodeExists returns pathnotfound exception instead of true or false | Community
Skip to main content
vikramca06
Level 4
January 30, 2019
Solved

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

  • January 30, 2019
  • 8 replies
  • 5668 views

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.

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

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

8 replies

Gaurav-Behl
Level 10
January 30, 2019

How are you getting the session? Does the service-user that you use has "read" access on that path?

vikramca06
Level 4
January 30, 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

smacdonald2008
Level 10
January 30, 2019

Use javax.jcr.Node's method named hasNode() - see Javadocs.

Node (Content Repository for Java Technology API Version 2.0) 

This method returns false if this node does not exist.

antoniom5495929
Level 7
January 30, 2019

Hi,

could you post the stacktrace? It seems an interesting behavior.

Thanks,

Antonio

smacdonald2008
Level 10
January 30, 2019

For testing sake - use the admin login call to get session and whitelist the OSGi bundle. See if the API works properly then.

vikramca06
Level 4
January 31, 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]

antoniom5495929
Level 7
January 31, 2019

Hi,

could you attach the entire java class? Just to try to reproduce it.

Thanks,

Antonio

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
January 31, 2019

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