incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r780748 - in /incubator/sling/trunk/bundles/api/src: main/java/org/apache/sling/api/resource/ResourceUtil.java test/java/org/apache/sling/api/resource/ResourceUtilTest.java
Date Mon, 01 Jun 2009 17:49:17 GMT
Author: fmeschbe
Date: Mon Jun  1 17:49:17 2009
New Revision: 780748

URL: http://svn.apache.org/viewvc?rev=780748&view=rev
Log:
SLING-988 Ensure ResourceUtil.getValueMap does not throw a
NullPointerException (thanks Julian Sedding for providing
the patch)

Modified:
    incubator/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
    incubator/sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java

Modified: incubator/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java?rev=780748&r1=780747&r2=780748&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
(original)
+++ incubator/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
Mon Jun  1 17:49:17 2009
@@ -285,11 +285,14 @@
      * @param res The <code>Resource</code> to adapt to the value map.
      * @return A value map.
      */
+    @SuppressWarnings("unchecked")
     public static ValueMap getValueMap(final Resource res) {
-        ValueMap map = (res == null ? null : res.adaptTo(ValueMap.class));
-        if ( map == null ) {
+        ValueMap map = (res == null)
+                ? ValueMap.EMPTY
+                : res.adaptTo(ValueMap.class);
+        if (map == null) {
             Map m = res.adaptTo(Map.class);
-            if ( m != null ) {
+            if (m != null) {
                 map = new ValueMapDecorator(m);
             } else {
                 map = ValueMap.EMPTY;

Modified: incubator/sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java?rev=780748&r1=780747&r2=780748&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
(original)
+++ incubator/sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
Mon Jun  1 17:49:17 2009
@@ -147,4 +147,11 @@
         assertEquals("b", ResourceUtil.getName("/b/c/.."));
         assertEquals("", ResourceUtil.getName("/b/c/../.."));
     }
+
+    public void testGetValueMap() {
+        // expect an empty ValueMap 
+        ValueMap valueMap = ResourceUtil.getValueMap(null);
+        assertNotNull(valueMap);
+        assertEquals(0, valueMap.size());
+    }
 }



Mime
View raw message