You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2013/09/09 10:42:36 UTC

git commit: FIx NPE in RefScenario when a complex property is missing

Updated Branches:
  refs/heads/master 5457e7739 -> 44d62897a


FIx NPE in RefScenario when a complex property is missing


Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/44d62897
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/44d62897
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/44d62897

Branch: refs/heads/master
Commit: 44d62897a1c13bb2ece77a33c92580d28cc9cbb6
Parents: 5457e77
Author: Christian Amend <ch...@apache.org>
Authored: Mon Sep 9 10:38:57 2013 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Mon Sep 9 10:38:57 2013 +0200

----------------------------------------------------------------------
 .../odata2/fit/ref/EntryXmlChangeTest.java      | 22 ++++++++++++++++++++
 .../odata2/ref/processor/ListsProcessor.java    |  7 ++++---
 2 files changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/44d62897/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlChangeTest.java
----------------------------------------------------------------------
diff --git a/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlChangeTest.java b/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlChangeTest.java
index 752feb2..67304f8 100644
--- a/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlChangeTest.java
+++ b/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlChangeTest.java
@@ -236,6 +236,28 @@ public class EntryXmlChangeTest extends AbstractRefXmlTest {
   }
 
   @Test
+  public void updateIncomplete() throws Exception {
+    final String requestBody = "<entry xmlns=\"" + Edm.NAMESPACE_ATOM_2005 + "\"" + "\n"
+        + "       xmlns:d=\"" + Edm.NAMESPACE_D_2007_08 + "\"" + "\n"
+        + "       xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "\n"
+        + "  <m:properties><d:EmployeeName>Mister X</d:EmployeeName></m:properties>" + "\n"
+        + "</entry>";
+    putUri("Employees('1')", requestBody, HttpContentType.APPLICATION_ATOM_XML_ENTRY, HttpStatusCodes.NO_CONTENT);
+    final String body = getBody(callUri("Employees('1')"));
+    assertXpathEvaluatesTo("Mister X", "/atom:entry/m:properties/d:EmployeeName", body);
+    assertXpathEvaluatesTo("0", "/atom:entry/m:properties/d:Age", body);
+    assertXpathEvaluatesTo("true", "/atom:entry/m:properties/d:EntryDate/@m:null", body);
+
+    final String requestBody2 = requestBody.replace("<d:EmployeeName>Mister X</d:EmployeeName>",
+        "<d:Location><d:Country>Allemagne</d:Country></d:Location>");
+    putUri("Employees('1')", requestBody2, HttpContentType.APPLICATION_ATOM_XML_ENTRY, HttpStatusCodes.NO_CONTENT);
+    final String body2 = getBody(callUri("Employees('1')"));
+    assertXpathEvaluatesTo("Allemagne", "/atom:entry/m:properties/d:Location/d:Country", body2);
+    assertXpathEvaluatesTo("true", "/atom:entry/m:properties/d:Location/d:City/d:CityName/@m:null", body2);
+    assertXpathEvaluatesTo("true", "/atom:entry/m:properties/d:EmployeeName/@m:null", body2);
+  }
+
+  @Test
   public void updateUnknownProperty() throws Exception {
     final String requestBody = getBody(callUri("Employees('2')"))
         .replace("<d:Age>" + EMPLOYEE_2_AGE + "</d:Age>",

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/44d62897/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java b/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
index 8534381..95679fa 100644
--- a/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
+++ b/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
@@ -1539,12 +1539,13 @@ public class ListsProcessor extends ODataSingleProcessor {
       if (type instanceof EdmEntityType && ((EdmEntityType) type).getKeyProperties().contains(property)) {
         continue;
       }
-      if (!merge || valueMap.containsKey(propertyName)) {
+      if (!merge || valueMap != null && valueMap.containsKey(propertyName)) {
+        final Object value = valueMap == null ? null : valueMap.get(propertyName);
         if (property.isSimple()) {
-          setPropertyValue(data, property, valueMap.get(propertyName));
+          setPropertyValue(data, property, value);
         } else {
           @SuppressWarnings("unchecked")
-          final Map<String, Object> values = (Map<String, Object>) valueMap.get(propertyName);
+          final Map<String, Object> values = (Map<String, Object>) value;
           setStructuralTypeValuesFromMap(getPropertyValue(data, property), (EdmStructuralType) property.getType(), values, merge);
         }
       }