gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lewi...@apache.org
Subject git commit: GORA-364 MemStore.get fails with NPE when key is not set
Date Wed, 06 Aug 2014 00:41:35 GMT
Repository: gora
Updated Branches:
  refs/heads/master 22b5cf8e5 -> 89c025d2f


GORA-364 MemStore.get fails with NPE when key is not set


Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/89c025d2
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/89c025d2
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/89c025d2

Branch: refs/heads/master
Commit: 89c025d2f9e4ba19378eb15537104c8775bf2474
Parents: 22b5cf8
Author: Lewis John McGibbney <lewis.j.mcgibbney@jpl.nasa.gov>
Authored: Tue Aug 5 17:41:44 2014 -0700
Committer: Lewis John McGibbney <lewis.j.mcgibbney@jpl.nasa.gov>
Committed: Tue Aug 5 17:41:44 2014 -0700

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 ++
 .../org/apache/gora/memory/store/MemStore.java  |  3 ++
 .../apache/gora/memory/store/MemStoreTest.java  | 31 ++++++++++++++++++++
 3 files changed, 36 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/gora/blob/89c025d2/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 4fdb83b..01e14f9 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,8 @@
 
 Current Development 0.5-SNAPSHOT
 
+* GORA-364 MemStore.get fails with NPE when key is not set (Gerhard Gossen via lewismc)
+
 * GORA-189 Embrace all text-like parameters in generated Persistent subclasses by Compiler
CharSequence (lewismc)
 
 * GORA-361 AvroUtils.deepClonePersistent needs to flush BinaryEncoder (Gerhard Gossen via
hsaputra)

http://git-wip-us.apache.org/repos/asf/gora/blob/89c025d2/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java b/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java
index bc0d59f..56ba4e3 100644
--- a/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java
+++ b/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java
@@ -139,6 +139,9 @@ public class MemStore<K, T extends PersistentBase> extends DataStoreBase<K,
T> {
   @Override
   public T get(K key, String[] fields) {
     T obj = map.get(key);
+    if (obj == null) {
+      return null;
+    }
     return getPersistent(obj, getFieldsToQuery(fields));
   }
 

http://git-wip-us.apache.org/repos/asf/gora/blob/89c025d2/gora-core/src/test/java/org/apache/gora/memory/store/MemStoreTest.java
----------------------------------------------------------------------
diff --git a/gora-core/src/test/java/org/apache/gora/memory/store/MemStoreTest.java b/gora-core/src/test/java/org/apache/gora/memory/store/MemStoreTest.java
new file mode 100644
index 0000000..f715280
--- /dev/null
+++ b/gora-core/src/test/java/org/apache/gora/memory/store/MemStoreTest.java
@@ -0,0 +1,31 @@
+package org.apache.gora.memory.store;
+
+import org.apache.gora.examples.generated.WebPage;
+import org.apache.gora.store.DataStore;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assume.assumeTrue;
+
+public class MemStoreTest {
+
+  @Test
+  public void testGetMissingValue() {
+    DataStore<String, WebPage> store = new MemStore<String, WebPage>();
+    WebPage nullWebPage = store.get("missing", new String[0]);
+    assertNull(nullWebPage);
+    store.close();
+  }
+
+  @Test
+  public void testPutGet() throws Exception {
+    String key = "org.apache.gora:http:/";
+    DataStore<String, WebPage> store = new MemStore<String, WebPage>();
+    assumeTrue(store.get(key, new String[0]) == null);
+    store.put(key, WebPage.newBuilder().build());
+    assertNotNull(store.get(key, new String[0]));
+    store.close();
+  }
+
+}


Mime
View raw message