This is an automated email from the ASF dual-hosted git repository.

bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 728c393  GEODE-7794: Checking for null result and falling back to 
PdxInstance deserialization. (#575)
728c393 is described below

commit 728c393150c2a83dad2ba00318561844520de55e
Author: Matthew Reddington <mredding...@pivotal.io>
AuthorDate: Wed Feb 12 14:14:41 2020 -0800

    GEODE-7794: Checking for null result and falling back to PdxInstance 
deserialization. (#575)
    
    Fixes a bug where, when issuing two get() requests back-to-back for the 
same key, the second result returned is a PdxWrapper object with a shared 
pointer to null.
---
 cppcache/integration/test/PdxJsonTypeTest.cpp | 29 +++++++++++++++++++++++++++
 cppcache/src/PdxHelper.cpp                    |  9 +++++++++
 cppcache/src/PdxType.hpp                      |  9 +++++----
 3 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/cppcache/integration/test/PdxJsonTypeTest.cpp 
b/cppcache/integration/test/PdxJsonTypeTest.cpp
index e98eb48..33643dc 100644
--- a/cppcache/integration/test/PdxJsonTypeTest.cpp
+++ b/cppcache/integration/test/PdxJsonTypeTest.cpp
@@ -113,4 +113,33 @@ TEST(PdxJsonTypeTest, testCreateTwoJsonInstances) {
   EXPECT_EQ(pdxInstance->getIntField("baz"), 42);
 }
 
+TEST(PdxJsonTypeTest, testTwoConsecutiveGets) {
+  Cluster cluster{LocatorCount{1}, ServerCount{1}};
+  cluster.start();
+  cluster.getGfsh()
+      .create()
+      .region()
+      .withName("region")
+      .withType("REPLICATE")
+      .execute();
+
+  auto cache = cluster.createCache();
+  auto region = setupRegion(cache);
+  auto pdxInstanceFactory =
+      cache.createPdxInstanceFactory(gemfireJsonClassName);
+
+  pdxInstanceFactory.writeString("foo", "bar");
+  auto pdxInstance = pdxInstanceFactory.create();
+
+  region->put("simpleObject", pdxInstance);
+
+  auto cache2 = cluster.createCache();
+  auto region2 = setupRegion(cache2);
+
+  region2->get("simpleObject");  // Throw the first one away
+
+  EXPECT_TRUE(
+      std::dynamic_pointer_cast<PdxInstance>(region2->get("simpleObject")));
+}
+
 }  // namespace
diff --git a/cppcache/src/PdxHelper.cpp b/cppcache/src/PdxHelper.cpp
index fd5efdf..806b8d3 100644
--- a/cppcache/src/PdxHelper.cpp
+++ b/cppcache/src/PdxHelper.cpp
@@ -176,6 +176,15 @@ std::shared_ptr<PdxSerializable> 
PdxHelper::deserializePdx(DataInput& dataInput,
                 ->getExpiryTaskManager());  // it will set data in weakhashmap
       }
       prr.moveStream();
+
+      if (auto pdxWrapper =
+              std::dynamic_pointer_cast<PdxWrapper>(pdxObjectptr)) {
+        if (!pdxWrapper->getObject()) {
+          // No serializer was registered to deserialize this type.
+          // Fall back to PdxInstance
+          return nullptr;
+        }
+      }
     }
   } else {
     // type not found; need to get from server
diff --git a/cppcache/src/PdxType.hpp b/cppcache/src/PdxType.hpp
index b76b824..0ed16b0 100644
--- a/cppcache/src/PdxType.hpp
+++ b/cppcache/src/PdxType.hpp
@@ -43,10 +43,11 @@ typedef std::map<std::string, 
std::shared_ptr<PdxFieldType>> NameVsPdxType;
 class PdxType;
 class PdxTypeRegistry;
 
-class PdxType : public internal::DataSerializableInternal,
-                public std::enable_shared_from_this<PdxType>,
-                private NonCopyable,
-                private NonAssignable {
+class PdxType
+    : public internal::DataSerializableInternal,
+      public std::enable_shared_from_this<PdxType>,
+      private NonCopyable,
+      private NonAssignable {
  private:
   ACE_RW_Thread_Mutex m_lockObj;
 

Reply via email to