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 th...@apache.org on 2013/06/27 16:18:08 UTC

svn commit: r1497366 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java

Author: thomasm
Date: Thu Jun 27 14:18:07 2013
New Revision: 1497366

URL: http://svn.apache.org/r1497366
Log:
OAK-883 Possible NPE in ContentMirrorStoreStrategy.PathIterator

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java?rev=1497366&r1=1497365&r2=1497366&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java Thu Jun 27 14:18:07 2013
@@ -200,6 +200,9 @@ public class ContentMirrorStoreStrategy 
         }
         
         void setPathContainsValue(boolean pathContainsValue) {
+            if (init) {
+                throw new IllegalStateException("This iterator is already initialized");
+            }
             this.pathContainsValue = pathContainsValue;
         }
 
@@ -211,8 +214,28 @@ public class ContentMirrorStoreStrategy 
             }
             return !closed;
         }
-        
+
         private void fetchNext() {
+            while (true) {
+                fetchNextPossiblyDuplicate();
+                if (closed) {
+                    return;
+                }
+                if (pathContainsValue) {
+                    String value = PathUtils.elements(currentPath).iterator().next();
+                    currentPath = PathUtils.relativize(value, currentPath);
+                    // don't return duplicate paths:
+                    // Set.add returns true if the entry was new,
+                    // so if it returns false, it was already known
+                    if (!knownPaths.add(currentPath)) {
+                        continue;
+                    }
+                }
+                break;
+            }
+        }
+        
+        private void fetchNextPossiblyDuplicate() {
             while (!nodeIterators.isEmpty()) {
                 Iterator<? extends ChildNodeEntry> iterator = nodeIterators.getLast();
                 if (iterator.hasNext()) {
@@ -247,7 +270,6 @@ public class ContentMirrorStoreStrategy 
             closed = true;
         }
 
-
         @Override
         public String next() {
             if (closed) {
@@ -257,23 +279,11 @@ public class ContentMirrorStoreStrategy 
                 fetchNext();
                 init = true;
             }
-            while (true) {
-                String result = currentPath;
-                fetchNext();
-                if (pathContainsValue) {
-                    String value = PathUtils.elements(result).iterator().next();
-                    result = PathUtils.relativize(value, result);
-                    // don't return duplicate paths:
-                    // Set.add returns true if the entry was new,
-                    // so if it returns false, it was already known
-                    if (!knownPaths.add(result)) {
-                        continue;
-                    }
-                }
-                return result;
-            }
+            String result = currentPath;
+            fetchNext();
+            return result;
         }
-
+        
         @Override
         public void remove() {
             throw new UnsupportedOperationException();