summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2018-09-17 13:36:13 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2018-09-17 13:37:05 +0200
commit8815babcd93c17d9b904568f9cd0434d659a2840 (patch)
treea55d35ead790a2d9f27dcaca32dd2c80365db42f /document
parenta940b388669b3ad3cc364c6f6ce638919ee76676 (diff)
Avoid NPE on non-exiting field
Diffstat (limited to 'document')
-rw-r--r--document/src/main/java/com/yahoo/document/DocumentUpdate.java6
-rw-r--r--document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java4
2 files changed, 7 insertions, 3 deletions
diff --git a/document/src/main/java/com/yahoo/document/DocumentUpdate.java b/document/src/main/java/com/yahoo/document/DocumentUpdate.java
index 301d6af0f54..028215c0d6c 100644
--- a/document/src/main/java/com/yahoo/document/DocumentUpdate.java
+++ b/document/src/main/java/com/yahoo/document/DocumentUpdate.java
@@ -278,7 +278,8 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
* @return the update for the field, or null if that field has no update in this
*/
public FieldUpdate getFieldUpdate(String fieldName) {
- return getFieldUpdate(documentType.getField(fieldName));
+ Field field = documentType.getField(fieldName);
+ return field != null ? getFieldUpdate(field) : null;
}
private FieldUpdate getFieldUpdateById(Integer fieldId) {
return id2FieldUpdateMap.get(fieldId);
@@ -396,7 +397,8 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
}
public FieldUpdate removeFieldUpdate(String fieldName) {
- return removeFieldUpdate(documentType.getField(fieldName));
+ Field field = documentType.getField(fieldName);
+ return field != null ? removeFieldUpdate(field) : null;
}
/**
diff --git a/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java b/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java
index 53f68ca182c..a9f77cb5eb0 100644
--- a/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java
+++ b/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java
@@ -442,7 +442,7 @@ public class DocumentUpdateTestCase {
}
@Test
- public void testgetAndRemoveByName() {
+ public void testGetAndRemoveByName() {
DocumentType docType = new DocumentType("my_type");
Field my_int = new Field("my_int", DataType.INT);
Field your_int = new Field("your_int", DataType.INT);
@@ -451,6 +451,8 @@ public class DocumentUpdateTestCase {
DocumentUpdate update = new DocumentUpdate(docType, new DocumentId("doc:this:is:a:test"));
update.addFieldUpdate(FieldUpdate.createAssign(my_int, new IntegerFieldValue(2)));
+ assertNull(update.getFieldUpdate("none-existing-field"));
+ assertNull(update.removeFieldUpdate("none-existing-field"));
assertNull(update.getFieldUpdate("your_int"));
assertEquals(new IntegerFieldValue(2), update.getFieldUpdate("my_int").getValueUpdate(0).getValue());
assertNull(update.removeFieldUpdate("your_int"));