### Eclipse Workspace Patch 1.0 #P jackrabbit-core Index: src/main/java/org/apache/jackrabbit/core/persistence/pool/BundleDbPersistenceManager.java =================================================================== --- src/main/java/org/apache/jackrabbit/core/persistence/pool/BundleDbPersistenceManager.java (revision 1067913) +++ src/main/java/org/apache/jackrabbit/core/persistence/pool/BundleDbPersistenceManager.java (working copy) @@ -28,7 +28,9 @@ import java.sql.Types; import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; import java.util.List; +import java.util.Random; import javax.jcr.RepositoryException; import javax.sql.DataSource; @@ -58,6 +60,7 @@ import org.apache.jackrabbit.core.util.db.DatabaseAware; import org.apache.jackrabbit.core.util.db.DbUtility; import org.apache.jackrabbit.core.util.db.StreamWrapper; +import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -751,6 +754,26 @@ if (loadBundle(parentId) == null) { log.error("NodeState '" + id + "' references inexistent parent uuid '" + parentId + "'"); } + NodePropBundle parentBundle = loadBundle(parentId); + Iterator childNodeIter = parentBundle.getChildNodeEntries().iterator(); + boolean found = false; + while (childNodeIter.hasNext()) { + NodePropBundle.ChildNodeEntry entry = childNodeIter.next(); + if (entry.getId().equals(id)){ + found = true; + break; + } + } + if (!found) { + log.error("NodeState '" + id + "' is not referenced by its parent node '" + parentId + "'"); + int l = (int) System.currentTimeMillis(); + int r = new Random().nextInt(); + int n = l + r; + String nodeName = Integer.toHexString(n); + parentBundle.addChildNodeEntry(NameFactoryImpl.getInstance().create("{}" + nodeName), id); + log.info("NodeState '" + id + "' adds itself to its parent node '" + parentId + "' with a new name '" + nodeName+ "'"); + modifications.add(parentBundle); + } } } catch (ItemStateException e) { log.error("Error reading node '" + parentId + "' (parent of '" + id + "'): " + e);