You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2022/02/25 16:11:49 UTC
[jackrabbit-oak] branch trunk updated: OAK-9709: PropertyDelegate.isProtected() throws NPE when parent is stale
This is an automated email from the ASF dual-hosted git repository.
mreutegg pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new a686a6e OAK-9709: PropertyDelegate.isProtected() throws NPE when parent is stale
new c6b0ddc Merge pull request #505 from mreutegg/OAK-9709
a686a6e is described below
commit a686a6ea3a968c46c4e5398ba7c1513d886500c8
Author: Marcel Reutegger <ma...@gmail.com>
AuthorDate: Fri Feb 25 15:44:13 2022 +0100
OAK-9709: PropertyDelegate.isProtected() throws NPE when parent is stale
---
.../oak/jcr/delegate/PropertyDelegate.java | 14 ++++++--
.../oak/jcr/delegate/PropertyDelegateTest.java | 37 ++++++++++++++++++++++
2 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegate.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegate.java
index 45b49e8..573ba75 100644
--- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegate.java
+++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegate.java
@@ -92,7 +92,12 @@ public class PropertyDelegate extends ItemDelegate {
@Override
public boolean isProtected() throws InvalidItemStateException {
- return getParent().isProtected(name);
+ NodeDelegate p = getParent();
+ if (p != null) {
+ return p.isProtected(name);
+ } else {
+ throw newInvalidItemStateException();
+ }
}
@NotNull
@@ -100,8 +105,7 @@ public class PropertyDelegate extends ItemDelegate {
if (state != null) {
return state;
} else {
- throw new InvalidItemStateException(
- "The " + name + " property does not exist");
+ throw newInvalidItemStateException();
}
}
@@ -160,4 +164,8 @@ public class PropertyDelegate extends ItemDelegate {
.toString();
}
+ private InvalidItemStateException newInvalidItemStateException() {
+ return new InvalidItemStateException(
+ "The " + name + " property does not exist");
+ }
}
diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegateTest.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegateTest.java
new file mode 100644
index 0000000..37b415b
--- /dev/null
+++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegateTest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.delegate;
+
+import javax.jcr.InvalidItemStateException;
+
+import org.apache.jackrabbit.oak.api.Tree;
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class PropertyDelegateTest extends AbstractDelegatorTest {
+
+ @Test(expected = InvalidItemStateException.class)
+ public void isProtectedOnStaleParent() throws InvalidItemStateException {
+ SessionDelegate sd = mockSessionDelegate();
+ Tree t = mock(Tree.class);
+ when(t.exists()).thenReturn(false);
+ PropertyDelegate pd = new PropertyDelegate(sd, t, "p");
+ pd.isProtected();
+ }
+}