Skip to content

Commit

Permalink
OAK-9709: PropertyDelegate.isProtected() throws NPE when parent is stale
Browse files Browse the repository at this point in the history
  • Loading branch information
mreutegg committed Feb 25, 2022
1 parent 1a372de commit a686a6e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,20 @@ public Status getStatus() {

@Override
public boolean isProtected() throws InvalidItemStateException {
return getParent().isProtected(name);
NodeDelegate p = getParent();
if (p != null) {
return p.isProtected(name);
} else {
throw newInvalidItemStateException();
}
}

@NotNull
public PropertyState getPropertyState() throws InvalidItemStateException {
if (state != null) {
return state;
} else {
throw new InvalidItemStateException(
"The " + name + " property does not exist");
throw newInvalidItemStateException();
}
}

Expand Down Expand Up @@ -160,4 +164,8 @@ public String toString() {
.toString();
}

private InvalidItemStateException newInvalidItemStateException() {
return new InvalidItemStateException(
"The " + name + " property does not exist");
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit a686a6e

Please sign in to comment.