incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1400860 - in /sling/trunk/bundles/resourceresolver/src: main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
Date Mon, 22 Oct 2012 12:20:23 GMT
Author: cziegeler
Date: Mon Oct 22 12:20:23 2012
New Revision: 1400860

URL: http://svn.apache.org/viewvc?rev=1400860&view=rev
Log:
SLING-2626 :  NPE in ResourceResolverImpl.getResource. Apply slightly modifed version of patch
from Radu Cotescu

Modified:
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
    sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java?rev=1400860&r1=1400859&r2=1400860&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
Mon Oct 22 12:20:23 2012
@@ -563,31 +563,32 @@ public class ResourceResolverImpl extend
     public Resource getResource(String path) {
         checkClosed();
 
-        // if the path is absolute, normalize . and .. segements and get res
-        if (path.startsWith("/")) {
-            path = ResourceUtil.normalize(path);
-            Resource result = (path != null) ? getResourceInternal(path) : null;
-            if (result != null) {
-                result = this.factory.getResourceDecoratorTracker().decorate(result);
-                return result;
-            }
-            return null;
-        }
-
-        // otherwise we have to apply the search path
-        // (don't use this.getSearchPath() to save a few cycle for not cloning)
-        final String[] paths = factory.getSearchPath();
-        if (paths != null) {
-            for (final String prefix : factory.getSearchPath()) {
-                final Resource res = getResource(prefix + path);
-                if (res != null) {
-                    return res;
+        Resource result = null;
+        if ( path != null ) {
+            // if the path is absolute, normalize . and .. segments and get res
+            if (path.startsWith("/")) {
+                path = ResourceUtil.normalize(path);
+                result = (path != null) ? getResourceInternal(path) : null;
+                if (result != null) {
+                    result = this.factory.getResourceDecoratorTracker().decorate(result);
+                }
+            } else {
+
+                // otherwise we have to apply the search path
+                // (don't use this.getSearchPath() to save a few cycle for not cloning)
+                final String[] paths = factory.getSearchPath();
+                if (paths != null) {
+                    for (final String prefix : factory.getSearchPath()) {
+                        result = getResource(prefix + path);
+                        if (result != null) {
+                            break;
+                        }
+                    }
                 }
             }
         }
 
-        // no resource found, if we get here
-        return null;
+        return result;
     }
 
     /**
@@ -597,7 +598,7 @@ public class ResourceResolverImpl extend
     public Resource getResource(final Resource base, String path) {
         checkClosed();
 
-        if (!path.startsWith("/") && base != null) {
+        if (path != null && !path.startsWith("/") && base != null) {
             path = base.getPath() + "/" + path;
         }
 

Modified: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java?rev=1400860&r1=1400859&r2=1400860&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
Mon Oct 22 12:20:23 2012
@@ -176,26 +176,26 @@ public class ResourceResolverImplTest {
         final Resource res00 = resResolver.resolve((String) null);
         assertNotNull(res00);
         assertTrue("Resource must be NonExistingResource",
-                        res00 instanceof NonExistingResource);
+                res00 instanceof NonExistingResource);
         assertEquals("Null path is expected to return root", "/",
-            res00.getPath());
+                res00.getPath());
 
         // relative paths are treated as if absolute
         final String path01 = "relPath/relPath";
         final Resource res01 = resResolver.resolve(path01);
         assertNotNull(res01);
         assertEquals("Expecting absolute path for relative path", "/" + path01,
-            res01.getPath());
+                res01.getPath());
         assertTrue("Resource must be NonExistingResource",
-            res01 instanceof NonExistingResource);
+                res01 instanceof NonExistingResource);
 
         final String no_resource_path = "/no_resource/at/this/location";
         final Resource res02 = resResolver.resolve(no_resource_path);
         assertNotNull(res02);
         assertEquals("Expecting absolute path for relative path",
-            no_resource_path, res02.getPath());
+                no_resource_path, res02.getPath());
         assertTrue("Resource must be NonExistingResource",
-            res01 instanceof NonExistingResource);
+                res01 instanceof NonExistingResource);
 
         try {
             resResolver.resolve((HttpServletRequest) null);
@@ -207,25 +207,34 @@ public class ResourceResolverImplTest {
         final Resource res0 = resResolver.resolve(null, no_resource_path);
         assertNotNull("Expecting resource if resolution fails", res0);
         assertTrue("Resource must be NonExistingResource",
-            res0 instanceof NonExistingResource);
+                res0 instanceof NonExistingResource);
         assertEquals("Path must be the original path", no_resource_path,
-            res0.getPath());
+                res0.getPath());
 
         final HttpServletRequest req1 = new ResourceResolverTestRequest(
-            no_resource_path);
+                no_resource_path);
         final Resource res1 = resResolver.resolve(req1);
         assertNotNull("Expecting resource if resolution fails", res1);
         assertTrue("Resource must be NonExistingResource",
-            res1 instanceof NonExistingResource);
+                res1 instanceof NonExistingResource);
         assertEquals("Path must be the original path", no_resource_path,
-            res1.getPath());
+                res1.getPath());
 
         final HttpServletRequest req2 = new ResourceResolverTestRequest(null);
         final Resource res2 = resResolver.resolve(req2);
         assertNotNull("Expecting resource if resolution fails", res2);
         assertTrue("Resource must be NonExistingResource",
-            res2 instanceof NonExistingResource);
+                res2 instanceof NonExistingResource);
         assertEquals("Path must be the the root path", "/", res2.getPath());
+
+        final Resource res3 = resResolver.getResource(null);
+        assertNull("Expected null resource for null path", res3);
+
+        final Resource res4 = resResolver.getResource(null, null);
+        assertNull("Expected null resource for null path", res4);
+
+        final Resource res5 = resResolver.getResource(res01, null);
+        assertNull("Expected null resource for null path", res5);
     }
 
     @Test public void test_clone_based_on_anonymous() throws Exception {
@@ -297,7 +306,7 @@ public class ResourceResolverImplTest {
         assertTrue(validNames.remove(names.next()));
         assertFalse("Expect no more names", names.hasNext());
         assertTrue("Expect validNames set to be empty now",
-            validNames.isEmpty());
+                validNames.isEmpty());
 
         rr.close();
     }



Mime
View raw message