Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java (revision 29d3d8f1384f78e35039c8cb8503db67ae37496c) +++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java (revision ) @@ -18,30 +18,24 @@ */ package org.apache.jackrabbit.oak.jcr; -import static java.util.Arrays.asList; -import static javax.jcr.ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW; -import static org.apache.jackrabbit.JcrConstants.JCR_UUID; -import static org.apache.jackrabbit.commons.JcrUtils.getChildNodes; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeTrue; +import org.apache.jackrabbit.JcrConstants; +import org.apache.jackrabbit.api.JackrabbitNode; +import org.apache.jackrabbit.api.JackrabbitRepository; +import org.apache.jackrabbit.api.ReferenceBinary; +import org.apache.jackrabbit.commons.cnd.CndImporter; +import org.apache.jackrabbit.commons.cnd.ParseException; +import org.apache.jackrabbit.commons.jackrabbit.SimpleReferenceBinary; +import org.apache.jackrabbit.core.data.RandomInputStream; +import org.apache.jackrabbit.oak.jcr.repository.RepositoryImpl; +import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants; +import org.apache.jackrabbit.spi.QValue; +import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver; +import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl; +import org.apache.jackrabbit.spi.commons.value.QValueValue; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.math.BigDecimal; -import java.util.Calendar; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - import javax.jcr.Binary; import javax.jcr.GuestCredentials; import javax.jcr.InvalidItemStateException; @@ -67,24 +61,29 @@ import javax.jcr.nodetype.NodeTypeManager; import javax.jcr.nodetype.NodeTypeTemplate; import javax.jcr.nodetype.PropertyDefinitionTemplate; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.math.BigDecimal; +import java.util.Calendar; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; -import org.apache.jackrabbit.JcrConstants; -import org.apache.jackrabbit.api.JackrabbitNode; -import org.apache.jackrabbit.api.JackrabbitRepository; -import org.apache.jackrabbit.api.ReferenceBinary; -import org.apache.jackrabbit.commons.cnd.CndImporter; -import org.apache.jackrabbit.commons.cnd.ParseException; -import org.apache.jackrabbit.commons.jackrabbit.SimpleReferenceBinary; -import org.apache.jackrabbit.core.data.RandomInputStream; -import org.apache.jackrabbit.oak.jcr.repository.RepositoryImpl; -import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants; -import org.apache.jackrabbit.spi.QValue; -import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver; -import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl; -import org.apache.jackrabbit.spi.commons.value.QValueValue; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import static java.util.Arrays.asList; +import static javax.jcr.ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW; +import static org.apache.jackrabbit.JcrConstants.JCR_UUID; +import static org.apache.jackrabbit.commons.JcrUtils.getChildNodes; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; public class RepositoryTest extends AbstractRepositoryTest { private static final String TEST_NODE = "test_node"; @@ -647,6 +646,26 @@ Node parentNode = getNode(TEST_PATH); addProperty(parentNode, "string", getAdminSession().getValueFactory().createValue("string value")); } + + @Test + public void testGetItemReturnsNodeBeforeProperty() throws RepositoryException { + String newNodeName = "getItemTest"; + String nodeAndPropertyName = "subnode"; + + Session session = getAdminSession(); + Node root = session.getRootNode(); + assertFalse(root.hasNode(newNodeName)); + Node newNode = root.addNode(newNodeName, NodeTypeConstants.NT_OAK_UNSTRUCTURED); + + newNode.setProperty(nodeAndPropertyName, "prop value"); + newNode.addNode(nodeAndPropertyName); + session.save(); + + Item item = session.getItem("/" + newNodeName + "/" + nodeAndPropertyName); + + assertTrue("should retrieve Node before property", item.isNode()); + } + @Test public void addMultiValuedString() throws RepositoryException { Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java (revision 29d3d8f1384f78e35039c8cb8503db67ae37496c) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java (revision ) @@ -16,31 +16,6 @@ */ package org.apache.jackrabbit.oak.jcr.delegate; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static java.util.concurrent.TimeUnit.NANOSECONDS; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_READ_COUNTER; -import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_READ_DURATION; -import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_WRITE_COUNTER; -import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_WRITE_DURATION; -import static org.apache.jackrabbit.oak.commons.PathUtils.denotesRoot; - -import java.io.IOException; -import java.util.Iterator; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.locks.Condition; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; -import javax.jcr.ItemExistsException; -import javax.jcr.PathNotFoundException; -import javax.jcr.RepositoryException; -import javax.jcr.nodetype.ConstraintViolationException; - import com.google.common.collect.ImmutableMap; import org.apache.jackrabbit.oak.api.AuthInfo; import org.apache.jackrabbit.oak.api.CommitFailedException; @@ -65,6 +40,30 @@ import org.slf4j.Marker; import org.slf4j.MarkerFactory; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; +import javax.jcr.ItemExistsException; +import javax.jcr.PathNotFoundException; +import javax.jcr.RepositoryException; +import javax.jcr.nodetype.ConstraintViolationException; +import java.io.IOException; +import java.util.Iterator; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static java.util.concurrent.TimeUnit.NANOSECONDS; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_READ_COUNTER; +import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_READ_DURATION; +import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_WRITE_COUNTER; +import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_WRITE_DURATION; +import static org.apache.jackrabbit.oak.commons.PathUtils.denotesRoot; + /** * TODO document */ @@ -426,12 +425,12 @@ return getRootNode(); } else { Tree parent = root.getTree(PathUtils.getParentPath(path)); - if (parent.hasProperty(name)) { - return new PropertyDelegate(this, parent, name); - } + Tree child = parent.getChild(name); if (child.exists()) { return new NodeDelegate(this, child); + } else if (parent.hasProperty(name)) { + return new PropertyDelegate(this, parent, name); } else { return null; }