[dna-commits] DNA SVN: r1181 - in trunk: dna-jcr/src/main/java/org/jboss/dna/jcr and 1 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Fri Aug 28 11:55:29 EDT 2009


Author: rhauch
Date: 2009-08-28 11:55:28 -0400 (Fri, 28 Aug 2009)
New Revision: 1181

Modified:
   trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/SvnAndJcrIntegrationTest.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
   trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
Log:
DNA-505 Svn Repository Source with NPE and other issues while opening connection through Jcr

A user reported an NPE, which I wasn't able to reproduce, but I changed AbstractJcrNode.toString() to better handle this situation if it should arise.  However, it shouldn't really be happening in the first place, so I've made a few other changes to try and further prevent this NPE.

First, the PropertyIterator should never expose a null Property, so the code that is creating this (and the underlying collection of Property objects) was changed to never add a null reference to the collection.

Second, the SVN connector had one case where it *might* add a null property object to the resulting nodes, so the code was changed to handle this case.

Modified: trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/SvnAndJcrIntegrationTest.java
===================================================================
--- trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/SvnAndJcrIntegrationTest.java	2009-08-28 15:26:27 UTC (rev 1180)
+++ trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/SvnAndJcrIntegrationTest.java	2009-08-28 15:55:28 UTC (rev 1181)
@@ -83,10 +83,11 @@
 
     @Test
     public void shouldIterateOverChildrenOfRoot() throws Exception {
+        System.out.println("Getting the root node and it's children ...");
         NodeIterator nodeIterator = this.session.getRootNode().getNodes();
 
         while (nodeIterator.hasNext()) {
-            System.out.println(nodeIterator.nextNode().getPath());
+            System.out.println(nodeIterator.nextNode());
         }
         assertThat(this.session.getRootNode().getNode("dna-graph"), is(notNullValue()));
     }

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java	2009-08-28 15:26:27 UTC (rev 1180)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java	2009-08-28 15:55:28 UTC (rev 1181)
@@ -1690,7 +1690,7 @@
             StringBuffer propertyBuff = new StringBuffer();
             while (iter.hasNext()) {
                 AbstractJcrProperty prop = (AbstractJcrProperty)iter.nextProperty();
-                propertyBuff.append(prop.toString()).append(", ");
+                propertyBuff.append(prop).append(", ");
             }
             return this.getPath() + " {" + propertyBuff.toString() + "}";
         } catch (RepositoryException re) {

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java	2009-08-28 15:26:27 UTC (rev 1180)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java	2009-08-28 15:55:28 UTC (rev 1181)
@@ -599,7 +599,8 @@
                 Name propertyName = property.getName();
                 if (propertyName.equals(JcrLexicon.UUID) && !isReferenceable(node)) continue;
                 if (!propertyName.getNamespaceUri().equals(DnaIntLexicon.Namespace.URI)) {
-                    result.add(property.getPayload().getJcrProperty());
+                    AbstractJcrProperty prop = property.getPayload().getJcrProperty();
+                    if (prop != null) result.add(prop);
                 }
             }
             return result;

Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java	2009-08-28 15:26:27 UTC (rev 1180)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java	2009-08-28 15:55:28 UTC (rev 1181)
@@ -131,6 +131,15 @@
         this.accessData = accessData;
     }
 
+    protected void addProperty( List<Property> properties,
+                                PropertyFactory factory,
+                                Name propertyName,
+                                Object value ) {
+        if (value != null) {
+            properties.add(factory.create(propertyName, value));
+        }
+    }
+
     protected boolean readNode( String workspaceName,
                                 Location myLocation,
                                 List<Property> properties,
@@ -186,10 +195,10 @@
                     }
                     if (properties != null) {
                         // Load the properties for this directory ......
-                        properties.add(factory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FOLDER));
+                        addProperty(properties, factory, JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FOLDER);
                         SVNDirEntry entry = getEntryInfo(workspaceRoot, directoryPath);
                         if (entry != null) {
-                            properties.add(factory.create(JcrLexicon.LAST_MODIFIED, dateFactory.create(entry.getDate())));
+                            addProperty(properties, factory, JcrLexicon.LAST_MODIFIED, dateFactory.create(entry.getDate()));
                         }
                     }
                 } else {
@@ -205,8 +214,8 @@
                             SVNDirEntry entry = getEntryInfo(workspaceRoot, contentPath);
                             if (entry != null) {
                                 // The request is to get properties of the "jcr:content" child node ...
-                                properties.add(factory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.RESOURCE));
-                                properties.add(factory.create(JcrLexicon.LAST_MODIFIED, dateFactory.create(entry.getDate())));
+                                addProperty(properties, factory, JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.RESOURCE);
+                                addProperty(properties, factory, JcrLexicon.LAST_MODIFIED, dateFactory.create(entry.getDate()));
                             }
 
                             ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -214,12 +223,12 @@
                             getData(contentPath, fileProperties, os);
                             String mimeType = fileProperties.getStringValue(SVNProperty.MIME_TYPE);
                             if (mimeType == null) mimeType = DEFAULT_MIME_TYPE;
-                            properties.add(factory.create(JcrLexicon.MIMETYPE, mimeType));
+                            addProperty(properties, factory, JcrLexicon.MIMETYPE, mimeType);
 
                             if (os.toByteArray().length > 0) {
                                 // Now put the file's content into the "jcr:data" property ...
                                 BinaryFactory binaryFactory = getExecutionContext().getValueFactories().getBinaryFactory();
-                                properties.add(factory.create(JcrLexicon.DATA, binaryFactory.create(os.toByteArray())));
+                                addProperty(properties, factory, JcrLexicon.DATA, binaryFactory.create(os.toByteArray()));
                             }
                         }
                     } else {
@@ -235,14 +244,12 @@
                         }
                         if (properties != null) {
                             // Now add the properties to "nt:file" ...
-                            properties.add(factory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FILE));
+                            addProperty(properties, factory, JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FILE);
                             ByteArrayOutputStream os = new ByteArrayOutputStream();
                             SVNProperties fileProperties = new SVNProperties();
                             getData(filePath, fileProperties, os);
                             String created = fileProperties.getStringValue(SVNProperty.COMMITTED_DATE);
-                            if (created != null) {
-                                properties.add(factory.create(JcrLexicon.CREATED, dateFactory.create(created)));
-                            }
+                            addProperty(properties, factory, JcrLexicon.CREATED, dateFactory.create(created));
                         }
                     }
                 }



More information about the dna-commits mailing list