anchela commented on code in PR #1781:
URL: https://github.com/apache/jackrabbit-oak/pull/1781#discussion_r1800532606


##########
oak-jackrabbit-api/src/main/java/org/apache/jackrabbit/api/JackrabbitNode.java:
##########
@@ -87,4 +89,18 @@ void setMixins(String[] mixinNames)
             return null;
         }
     }
+
+    /**
+     * Same as {@link #getParent()}, but instead of throwing an 
ItemNotFoundException or AccessDeniedException 
+     * just return {@code null}.
+     * @return the parent node, or {@code null} if there is no parent or the 
parent node is not accessible.
+     * @throws RepositoryException if an error occurs.
+     */
+    default @Nullable Node getParentOrNull() throws RepositoryException {
+        try {
+            return getParent();
+        } catch (ItemNotFoundException | AccessDeniedException e) {
+            return null;

Review Comment:
   i would add some debug log message in case of exception that allows to 
troubleshoot. wdyt?



##########
oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java:
##########
@@ -1679,6 +1679,24 @@ public PropertyImpl performNullable() throws 
RepositoryException {
         });
     }
 
+    @Override
+    public Node getParentOrNull() throws RepositoryException {
+        return perform(new NodeOperation<Node>(dlg, "getParentOrNull") {
+            @Override
+            public Node perform() throws RepositoryException {

Review Comment:
   i would also recommend to annotated the return value with @NotNull.
   the method should be renamed to `performNullable` for consistency



##########
oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java:
##########
@@ -1679,6 +1679,24 @@ public PropertyImpl performNullable() throws 
RepositoryException {
         });
     }
 
+    @Override
+    public Node getParentOrNull() throws RepositoryException {
+        return perform(new NodeOperation<Node>(dlg, "getParentOrNull") {

Review Comment:
   @stefan-egli , i agree. it should call performNullable such as it's done in 
`Node.getNodeOrNull`.



##########
oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java:
##########
@@ -1679,6 +1679,24 @@ public PropertyImpl performNullable() throws 
RepositoryException {
         });
     }
 
+    @Override
+    public Node getParentOrNull() throws RepositoryException {

Review Comment:
   i would annotate the method's return value with @Nullable to make it super 
clear.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to