jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1437975 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
Date Thu, 24 Jan 2013 12:29:23 GMT
Author: mduerig
Date: Thu Jan 24 12:29:23 2013
New Revision: 1437975

URL: http://svn.apache.org/viewvc?rev=1437975&view=rev
Log:
OAK-582: Throw IllegalArgumentException on invalid paths instead of a RepositoryException
(subtype)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java?rev=1437975&r1=1437974&r2=1437975&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
Thu Jan 24 12:29:23 2013
@@ -149,12 +149,11 @@ public class NamePathMapperImpl implemen
         // identifier path?
         if (length > 0 && jcrPath.charAt(0) == '[') {
             if (jcrPath.charAt(length - 1) != ']') {
-                // TODO error handling?
-                log.debug("Could not parse path " + jcrPath + ": unterminated identifier");
-                return null;
+                String msg = "Could not parse path " + jcrPath + ": invalid or unterminated
identifier";
+                log.debug(msg);
+                throw new IllegalArgumentException(msg);
             }
             if (this.idManager == null) {
-                // TODO error handling?
                 log.debug("Could not parse path " + jcrPath + ": could not resolve identifier");
                 return null;
             }
@@ -196,8 +195,9 @@ public class NamePathMapperImpl implemen
                     return jcrPath;
                 }
                 else {
-                    log.debug("Invalid path: {}", jcrPath);
-                    return null;
+                    String msg = "Invalid path: " + jcrPath;
+                    log.debug(msg);
+                    throw new IllegalArgumentException(msg);
                 }
             }
         }
@@ -207,18 +207,18 @@ public class NamePathMapperImpl implemen
         PathListener listener = new PathListener() {
             @Override
             public void error(String message) {
-                parseErrors.append(message);
+                throw new IllegalArgumentException(message);
             }
 
             @Override
             public boolean name(String name, int index) {
                 if (!keepIndex && index > 1) {
-                    error("index > 1");
+                    parseErrors.append("index > 1");
                     return false;
                 }
                 String p = nameMapper.getOakNameOrNull(name);
                 if (p == null) {
-                    error("Invalid name: " + name);
+                    parseErrors.append("Invalid name: ").append(name);
                     return false;
                 }
                 if (keepIndex && index > 0) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java?rev=1437975&r1=1437974&r2=1437975&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
Thu Jan 24 12:29:23 2013
@@ -22,14 +22,12 @@ import java.util.Map;
 
 import javax.jcr.RepositoryException;
 
+import com.google.common.collect.ImmutableMap;
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
 import org.junit.Test;
 
-import com.google.common.collect.ImmutableMap;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
 
 public class NamePathMapperImplTest {
@@ -65,7 +63,10 @@ public class NamePathMapperImplTest {
         invalid.add('[' + uuid + "]/a/b/c");
 
         for (String jcrPath : invalid) {
-            assertNull(npMapper.getOakPath(jcrPath));
+            try {
+                npMapper.getOakPath(jcrPath);
+                fail("Expected IllegalArgumentException for path: " + jcrPath);
+            } catch (IllegalArgumentException ignore) {}
         }
     }
 
@@ -168,11 +169,14 @@ public class NamePathMapperImplTest {
 
     @Test
     public void testInvalidJcrPaths() {
-        assertNull(npMapper.getOakPath("//"));
-        assertNull(npMapper.getOakPath("/foo//"));
-        assertNull(npMapper.getOakPath("/..//"));
-        assertNull(npMapper.getOakPath("/.."));
-        assertNull(npMapper.getOakPath("/foo/../.."));
+        String[] paths = {"//", "/foo//", "/..//", "/..", "/foo/../.."};
+
+        for (String path : paths) {
+            try {
+                npMapper.getOakPath(path);
+                fail("Expected IllegalArgumentException for path " + path);
+            } catch (IllegalArgumentException ignore) {}
+        }
     }
 
     @Test



Mime
View raw message