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 tr...@apache.org on 2013/11/26 11:25:12 UTC

svn commit: r1545598 - in /jackrabbit/oak/trunk/oak-jcr/src: main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java

Author: tripod
Date: Tue Nov 26 10:25:11 2013
New Revision: 1545598

URL: http://svn.apache.org/r1545598
Log:
OAK-1216 Path parsing must support SNS indexes, irrespective of SNS support

- check for SNS paths and throw PathNotFoundException

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java?rev=1545598&r1=1545597&r2=1545598&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java Tue Nov 26 10:25:11 2013
@@ -328,7 +328,13 @@ public class SessionContext implements N
         if (oakPath != null) {
             return oakPath;
         } else {
-            throw new RepositoryException("Invalid name or path: " + jcrPath);
+            // check if the path is an SNS path with an index > 1 and throw a PathNotFoundException instead (see OAK-1216)
+            if (getOakPathKeepIndex(jcrPath) != null) {
+                throw new PathNotFoundException(jcrPath);
+            } else {
+                throw new RepositoryException("Invalid name or path: " + jcrPath);
+            }
+
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java?rev=1545598&r1=1545597&r2=1545598&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java Tue Nov 26 10:25:11 2013
@@ -43,6 +43,7 @@ import javax.jcr.GuestCredentials;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.Item;
 import javax.jcr.ItemExistsException;
+import javax.jcr.ItemNotFoundException;
 import javax.jcr.NamespaceException;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.NoSuchWorkspaceException;
@@ -270,6 +271,36 @@ public class RepositoryTest extends Abst
         assertEquals("/foo", node.getPath());
     }
 
+    /**
+     * Test SNS 1-based indexed path.
+     * JCR 2.0, Chapter 22.2:
+     * <em>
+     *     A name in a content repository path that does not explicitly specify an index implies an index of 1.
+     *     For example, /a/b/c is equivalent to /a[1]/b[1]/c[1].
+     * </em>
+     *
+     * @throws RepositoryException
+     */
+    @Test
+    public void getNodeSNS() throws RepositoryException {
+        Node node = getNode("/foo[1]");
+        assertNotNull(node);
+        assertEquals("foo", node.getName());
+        assertEquals("/foo", node.getPath());
+
+        node.addNode("bar");
+        Node bar = getNode("/foo[1]/bar[1]");
+        assertEquals("/foo/bar", bar.getPath());
+
+        try {
+            getNode("/foo[1]/bar[2]");
+            fail("retrieving wrong SNS index should throw PathNotFoundException");
+        } catch (PathNotFoundException e) {
+            // expected.
+        }
+
+    }
+
     @Test(expected = RepositoryException.class)
     public void getNodeAbsolutePath() throws RepositoryException {
         Node root = getNode("/");