jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1000912 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/version/ test/java/org/apache/jackrabbit/core/version/
Date Fri, 24 Sep 2010 15:34:26 GMT
Author: jukka
Date: Fri Sep 24 15:34:25 2010
New Revision: 1000912

URL: http://svn.apache.org/viewvc?rev=1000912&view=rev
Log:
JCR-2655: initVersions crashes with NPE

Skip missing successors to avoid the NPE

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersion.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalXAVersionManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionIteratorImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersion.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersion.java?rev=1000912&r1=1000911&r2=1000912&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersion.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersion.java
Fri Sep 24 15:34:25 2010
@@ -21,6 +21,7 @@ import org.apache.jackrabbit.core.id.Nod
 import javax.jcr.version.Version;
 
 import java.util.Calendar;
+import java.util.List;
 
 /**
  * This interface defines the internal version.
@@ -63,7 +64,7 @@ public interface InternalVersion extends
      * @see javax.jcr.version.Version#getSuccessors()
      * @return the successors as internal versions
      */
-    InternalVersion[] getSuccessors();
+    List<InternalVersion> getSuccessors();
 
     /**
      * Equivalent to {@link Version#getLinearSuccessor()}.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java?rev=1000912&r1=1000911&r2=1000912&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
Fri Sep 24 15:34:25 2010
@@ -162,7 +162,7 @@ class InternalVersionHistoryImpl extends
         }
 
         // fix legacy
-        if (rootVersion.getSuccessors().length == 0) {
+        if (rootVersion.getSuccessors().isEmpty()) {
             for (Name versionName : nameCache.keySet()) {
                 InternalVersionImpl v = createVersionInstance(versionName);
                 v.legacyResolveSuccessors();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionImpl.java?rev=1000912&r1=1000911&r2=1000912&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionImpl.java
Fri Sep 24 15:34:25 2010
@@ -22,11 +22,14 @@ import org.apache.jackrabbit.core.value.
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import java.util.Arrays;
 import java.util.Calendar;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.ArrayList;
@@ -37,6 +40,10 @@ import java.util.ArrayList;
 class InternalVersionImpl extends InternalVersionItemImpl
         implements InternalVersion {
 
+    /** Logger instance */
+    private static final Logger log =
+        LoggerFactory.getLogger(InternalVersionImpl.class);
+
     /**
      * the date when this version was created
      */
@@ -138,18 +145,27 @@ class InternalVersionImpl extends Intern
     /**
      * {@inheritDoc}
      */
-    public InternalVersion[] getSuccessors() {
+    public List<InternalVersion> getSuccessors() {
         ReadLock lock = vMgr.acquireReadLock();
         try {
-            InternalValue[] values = node.getPropertyValues(NameConstants.JCR_SUCCESSORS);
+            InternalValue[] values =
+                node.getPropertyValues(NameConstants.JCR_SUCCESSORS);
             if (values != null) {
-                InternalVersion[] versions = new InternalVersion[values.length];
-                for (int i = 0; i < values.length; i++) {
-                    versions[i] = versionHistory.getVersion(values[i].getNodeId());
+                List<InternalVersion> versions =
+                    new ArrayList<InternalVersion>(values.length);
+                for (InternalValue value : values) {
+                    InternalVersion version =
+                        versionHistory.getVersion(value.getNodeId());
+                    if (version != null) {
+                        versions.add(version);
+                    } else {
+                        // Can happen with a corrupted repository (JCR-2655)
+                        log.warn("Missing successor {}", value.getNodeId());
+                    }
                 }
                 return versions;
             } else {
-                return new InternalVersion[0];
+                return Collections.emptyList();
             }
         } finally {
             lock.release();
@@ -275,8 +291,7 @@ class InternalVersionImpl extends Intern
      */
     void internalDetach() throws RepositoryException {
         // detach this from all successors
-        InternalVersion[] succ = getSuccessors();
-        for (InternalVersion aSucc : succ) {
+        for (InternalVersion aSucc :  getSuccessors()) {
             ((InternalVersionImpl) aSucc).internalDetachPredecessor(this, true);
         }
 
@@ -312,7 +327,7 @@ class InternalVersionImpl extends Intern
      */
     private void internalAddSuccessor(InternalVersionImpl succ, boolean store)
             throws RepositoryException {
-        List<InternalVersion> l = new ArrayList<InternalVersion>(Arrays.asList(getSuccessors()));
+        List<InternalVersion> l = new ArrayList<InternalVersion>(getSuccessors());
         if (!l.contains(succ)) {
             l.add(succ);
             storeXCessors(l, NameConstants.JCR_SUCCESSORS, store);
@@ -353,11 +368,11 @@ class InternalVersionImpl extends Intern
     private void internalDetachSuccessor(InternalVersionImpl v, boolean store)
             throws RepositoryException {
         // remove 'v' from successors list
-        List<InternalVersion> l = new ArrayList<InternalVersion>(Arrays.asList(getSuccessors()));
+        List<InternalVersion> l = new ArrayList<InternalVersion>(getSuccessors());
         l.remove(v);
 
         // attach V's successors
-        l.addAll(Arrays.asList(v.getSuccessors()));
+        l.addAll(v.getSuccessors());
         storeXCessors(l, NameConstants.JCR_SUCCESSORS, store);
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java?rev=1000912&r1=1000911&r2=1000912&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java
Fri Sep 24 15:34:25 2010
@@ -664,7 +664,7 @@ abstract class InternalVersionManagerBas
             return newVersionName;
         } else {
             // best is root version
-            return String.valueOf(best.getSuccessors().length + 1) + ".0";
+            return String.valueOf(best.getSuccessors().size() + 1) + ".0";
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalXAVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalXAVersionManager.java?rev=1000912&r1=1000911&r2=1000912&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalXAVersionManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalXAVersionManager.java
Fri Sep 24 15:34:25 2010
@@ -512,12 +512,10 @@ public class InternalXAVersionManager ex
             xaItems.put(history.getId(), history);
             // also put 'successor' and 'predecessor' version items to xaItem sets
             InternalVersion v = history.getVersion(name);
-            InternalVersion[] vs = v.getSuccessors();
-            for (InternalVersion v1 : vs) {
+            for (InternalVersion v1 : v.getSuccessors()) {
                 xaItems.put(v1.getId(), v1);
             }
-            vs = v.getPredecessors();
-            for (InternalVersion v1 : vs) {
+            for (InternalVersion v1 : v.getPredecessors()) {
                 xaItems.put(v1.getId(), v1);
             }
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java?rev=1000912&r1=1000911&r2=1000912&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java
Fri Sep 24 15:34:25 2010
@@ -34,6 +34,7 @@ import javax.jcr.RepositoryException;
 import javax.jcr.Node;
 import javax.jcr.nodetype.ConstraintViolationException;
 import java.util.Calendar;
+import java.util.List;
 
 /**
  * Base implementation of the {@link javax.jcr.version.Version} interface.
@@ -84,10 +85,11 @@ public class VersionImpl extends NodeImp
      */
     public javax.jcr.version.Version[] getSuccessors() throws RepositoryException {
         // need to wrap it around proper node
-        InternalVersion[] suc = getInternalVersion().getSuccessors();
-        Version[] ret = new Version[suc.length];
-        for (int i = 0; i < suc.length; i++) {
-            ret[i] = (Version) sessionContext.getSessionImpl().getNodeById(suc[i].getId());
+        List<InternalVersion> suc = getInternalVersion().getSuccessors();
+        Version[] ret = new Version[suc.size()];
+        for (int i = 0; i < ret.length; i++) {
+            ret[i] = (Version) sessionContext.getSessionImpl().getNodeById(
+                    suc.get(i).getId());
         }
         return ret;
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionIteratorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionIteratorImpl.java?rev=1000912&r1=1000911&r2=1000912&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionIteratorImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionIteratorImpl.java
Fri Sep 24 15:34:25 2010
@@ -26,7 +26,6 @@ import javax.jcr.version.VersionIterator
 import java.util.ConcurrentModificationException;
 import java.util.LinkedList;
 import java.util.NoSuchElementException;
-import java.util.Arrays;
 
 /**
  * This Class implements a VersionIterator that iterates over a version
@@ -170,8 +169,7 @@ class VersionIteratorImpl implements Ver
             NodeId id = currentVersion.getId();
             if (!versions.contains(id)) {
                 versions.add(id);
-                InternalVersion[] successors = currentVersion.getSuccessors();
-                workQueue.addAll(Arrays.asList(successors));
+                workQueue.addAll(currentVersion.getSuccessors());
             }
         }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java?rev=1000912&r1=1000911&r2=1000912&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
Fri Sep 24 15:34:25 2010
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.core.versi
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.LinkedList;
+import java.util.List;
 import java.util.Set;
 
 import javax.jcr.ItemExistsException;
@@ -577,14 +578,14 @@ abstract public class VersionManagerImpl
                     if (v == null) {
                         // if version selector was unable to select version,
                         // choose the initial one
-                        InternalVersion[] vs = vh.getRootVersion().getSuccessors();
-                        if (vs.length == 0) {
+                        List<InternalVersion> vs = vh.getRootVersion().getSuccessors();
+                        if (vs.isEmpty()) {
                             String msg = "Unable to select appropariate version for "
                                     + child.getName() + " using " + vsel;
                             log.error(msg);
                             throw new VersionException(msg);
                         }
-                        v = vs[0];
+                        v = vs.get(0);
                     }
                     InternalFrozenNode f = v.getFrozenNode();
                     restoredChild = state.addNode(fh.getName(), f.getFrozenPrimaryType(),
f.getFrozenId());

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java?rev=1000912&r1=1000911&r2=1000912&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java
Fri Sep 24 15:34:25 2010
@@ -16,7 +16,9 @@
  */
 package org.apache.jackrabbit.core.version;
 
+import java.util.Arrays;
 import java.util.Calendar;
+import java.util.List;
 
 import junit.framework.TestCase;
 
@@ -37,8 +39,8 @@ public class VersionIteratorImplTest ext
             this.id = id;
         }
 
-        public InternalVersion[] getSuccessors() {
-            return successors;
+        public List<InternalVersion> getSuccessors() {
+            return Arrays.asList(successors);
         }
 
         public NodeId getId() {



Mime
View raw message