sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1629608 - /sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java
Date Mon, 06 Oct 2014 10:34:09 GMT
Author: fmeschbe
Date: Mon Oct  6 10:34:08 2014
New Revision: 1629608

URL: http://svn.apache.org/r1629608
Log:
SLING-4007 Prevent NPE if Session is not available. Also don't call any code which makes use
   of the ValueFactory.

Modified:
    sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java

Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java?rev=1629608&r1=1629607&r2=1629608&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java
(original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java
Mon Oct  6 10:34:08 2014
@@ -32,7 +32,6 @@ import javax.jcr.Session;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 import javax.jcr.nodetype.NodeType;
-import javax.jcr.nodetype.NodeTypeIterator;
 import javax.jcr.nodetype.PropertyDefinition;
 
 import org.apache.sling.api.resource.ModifiableValueMap;
@@ -281,9 +280,6 @@ public class SlingPropertyValueHandler {
                 }
             }
 
-            // TODO - we should check for session
-            final ValueFactory valFac = parent.resource.getResourceResolver().adaptTo(Session.class).getValueFactory();
-
             final boolean multiValue = isMultiValue(parent, prop, values);
             final int type = getType(parent, prop);
 
@@ -292,13 +288,17 @@ public class SlingPropertyValueHandler {
                 removeIfSingleValueProperty(parent, prop);
             }
 
-            if (type == PropertyType.DATE) {
-                if (storeAsDate(parent, prop.getName(), values, multiValue, valFac)) {
-                    return;
-                }
-            } else if (isReferencePropertyType(type)) {
-                if (storeAsReference(parent, prop.getName(), values, type, multiValue, valFac))
{
-                    return;
+            Session s = parent.resource.getResourceResolver().adaptTo(Session.class);
+            if (s != null) {
+                final ValueFactory valFac = s.getValueFactory();
+                if (type == PropertyType.DATE) {
+                    if (storeAsDate(parent, prop.getName(), values, multiValue, valFac))
{
+                        return;
+                    }
+                } else if (isReferencePropertyType(type)) {
+                    if (storeAsReference(parent, prop.getName(), values, type, multiValue,
valFac)) {
+                        return;
+                    }
                 }
             }
 



Mime
View raw message