jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1336183 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/ oak-jcr/src/main/java/org/apa...
Date Wed, 09 May 2012 13:20:21 GMT
Author: jukka
Date: Wed May  9 13:20:19 2012
New Revision: 1336183

URL: http://svn.apache.org/viewvc?rev=1336183&view=rev
Log:
OAK-89: Improve exception handling

Proper handling of null return values from getOakName()

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeManagerImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java?rev=1336183&r1=1336182&r2=1336183&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java
Wed May  9 13:20:19 2012
@@ -57,7 +57,7 @@ public abstract class AbstractNameMapper
             String name = jcrName.substring(pos + 1);
             String oakPrefix = getOakPrefix(pref);
             if (oakPrefix == null) {
-                throw new IllegalArgumentException("prefix '" + pref + "' is not mapped"
);
+                return null; // not a mapped name
             } else {
                 return oakPrefix + ':' + name;
             }

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=1336183&r1=1336182&r2=1336183&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
Wed May  9 13:20:19 2012
@@ -108,6 +108,9 @@ public class NamePathMapperImpl implemen
             @Override
             public void name(String name) {
                 String p = nameMapper.getOakName(name);
+                if (p == null) {
+                    error("Invalid name: " + name);
+                }
                 elements.add(p);
             }
         };

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java?rev=1336183&r1=1336182&r2=1336183&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
Wed May  9 13:20:19 2012
@@ -172,10 +172,6 @@ abstract class ItemImpl extends Abstract
         return sessionDelegate.getValueFactory();
     }
 
-    String toOakName(String jcrName) {
-        return sessionDelegate.getNamePathMapper().getOakName(jcrName);
-    }
-    
     String toOakPath(String jcrPath) throws RepositoryException {
         try {
             return sessionDelegate.getOakPath(jcrPath);
@@ -185,10 +181,6 @@ abstract class ItemImpl extends Abstract
         }
     }
 
-    String toJcrName(String oakName) {
-        return sessionDelegate.getNamePathMapper().getJcrName(oakName);
-    }
-
     String toJcrPath(String oakPath) {
         return sessionDelegate.getNamePathMapper().getJcrPath(oakPath);
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1336183&r1=1336182&r2=1336183&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Wed May  9 13:20:19 2012
@@ -24,6 +24,8 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.jcr.util.LogUtil;
 import org.apache.jackrabbit.oak.jcr.value.ValueConverter;
+import org.apache.jackrabbit.oak.namepath.NameMapper;
+import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.util.Function1;
 import org.apache.jackrabbit.oak.util.Iterators;
 import org.apache.jackrabbit.oak.util.Predicate;
@@ -609,7 +611,12 @@ public class NodeImpl extends ItemImpl i
         checkStatus();
 
         // TODO: might be expanded, need a better way for this
-        String jcrName = toJcrName(toOakName(nodeTypeName));
+        NameMapper mapper = sessionDelegate.getNamePathMapper();
+        String oakName = mapper.getOakName(nodeTypeName);
+        if (oakName == null) {
+            return false; // An unknown name can't belong to a valid type
+        }
+        String jcrName = mapper.getJcrName(oakName);
 
         // TODO: figure out the right place for this check
         NodeTypeManager ntm = sessionDelegate.getNodeTypeManager();

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeManagerImpl.java?rev=1336183&r1=1336182&r2=1336183&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeManagerImpl.java
Wed May  9 13:20:19 2012
@@ -92,13 +92,15 @@ public class NodeTypeManagerImpl impleme
     @Override
     public boolean hasNodeType(String name) throws RepositoryException {
         init();
-        return typemap.containsKey(mapper.getOakName(name));
+        String oakName = mapper.getOakName(name); // can be null, which is fine
+        return typemap.containsKey(oakName);
     }
 
     @Override
     public NodeType getNodeType(String name) throws RepositoryException {
         init();
-        NodeType type = typemap.get(mapper.getOakName(name));
+        String oakName = mapper.getOakName(name); // can be null, which is fine
+        NodeType type = typemap.get(oakName);
         if (type == null) {
             throw new NoSuchNodeTypeException("Unknown node type: " + name);
         }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java?rev=1336183&r1=1336182&r2=1336183&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java
Wed May  9 13:20:19 2012
@@ -149,7 +149,11 @@ public class ValueFactoryImpl implements
         CoreValue cv;
         try {
             if (type == PropertyType.NAME) {
-                cv = factory.createValue(namePathMapper.getOakName(value), type);
+                String oakName = namePathMapper.getOakName(value);
+                if (oakName == null) {
+                    throw new ValueFormatException("Invalid name: " + value);
+                }
+                cv = factory.createValue(oakName, type);
             } else if (type == PropertyType.PATH) {
                 String oakPath = namePathMapper.getOakPath(value);
                 cv = factory.createValue(oakPath, type);
@@ -164,7 +168,7 @@ public class ValueFactoryImpl implements
         } catch (NumberFormatException e) {
             throw new ValueFormatException("Invalid value " + value + " for type " + PropertyType.nameFromValue(type));
         } catch (IllegalArgumentException e) {
-            // TODO: review exception handling in path/name resolution again
+            // TODO: review exception handling in path resolution again
             throw new ValueFormatException("Invalid value " + value + " for type " + PropertyType.nameFromValue(type));
         } catch (Exception e) {
             // TODO: review exception handling in path/name resolution again



Mime
View raw message