Repository: thrift
Updated Branches:
  refs/heads/master 170445644 -> 8f11f5234


THRIFT-3215 Replaces "throw new" in TJSONProtocol with a "throw" (+ testcase)

Sponsored-by: Roger Meier <[email protected]>
Signed-off-by: Claudius Heine <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/8f11f523
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/8f11f523
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/8f11f523

Branch: refs/heads/master
Commit: 8f11f52341f5984f77b2510094e51e6aef4c3552
Parents: 1704456
Author: Claudius Heine <[email protected]>
Authored: Wed Jul 1 10:35:38 2015 +0200
Committer: Roger Meier <[email protected]>
Committed: Wed Jul 8 11:26:51 2015 +0200

----------------------------------------------------------------------
 lib/cpp/src/thrift/protocol/TJSONProtocol.cpp |  8 ++++----
 lib/cpp/test/JSONProtoTest.cpp                | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/8f11f523/lib/cpp/src/thrift/protocol/TJSONProtocol.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/protocol/TJSONProtocol.cpp 
b/lib/cpp/src/thrift/protocol/TJSONProtocol.cpp
index 8d84e4b..e4077bc 100644
--- a/lib/cpp/src/thrift/protocol/TJSONProtocol.cpp
+++ b/lib/cpp/src/thrift/protocol/TJSONProtocol.cpp
@@ -806,7 +806,7 @@ uint32_t TJSONProtocol::readJSONInteger(NumberType& num) {
   try {
     num = boost::lexical_cast<NumberType>(str);
   } catch (boost::bad_lexical_cast e) {
-    throw new TProtocolException(TProtocolException::INVALID_DATA,
+    throw TProtocolException(TProtocolException::INVALID_DATA,
                                  "Expected numeric value; got \"" + str + 
"\"");
   }
   if (context_->escapeNum()) {
@@ -843,13 +843,13 @@ uint32_t TJSONProtocol::readJSONDouble(double& num) {
     } else {
       if (!context_->escapeNum()) {
         // Throw exception -- we should not be in a string in this case
-        throw new TProtocolException(TProtocolException::INVALID_DATA,
+        throw TProtocolException(TProtocolException::INVALID_DATA,
                                      "Numeric data unexpectedly quoted");
       }
       try {
         num = stringToDouble(str);
       } catch (std::runtime_error e) {
-        throw new TProtocolException(TProtocolException::INVALID_DATA,
+        throw TProtocolException(TProtocolException::INVALID_DATA,
                                      "Expected numeric value; got \"" + str + 
"\"");
       }
     }
@@ -862,7 +862,7 @@ uint32_t TJSONProtocol::readJSONDouble(double& num) {
     try {
       num = stringToDouble(str);
     } catch (std::runtime_error e) {
-      throw new TProtocolException(TProtocolException::INVALID_DATA,
+      throw TProtocolException(TProtocolException::INVALID_DATA,
                                    "Expected numeric value; got \"" + str + 
"\"");
     }
   }

http://git-wip-us.apache.org/repos/asf/thrift/blob/8f11f523/lib/cpp/test/JSONProtoTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/JSONProtoTest.cpp b/lib/cpp/test/JSONProtoTest.cpp
index da76802..f03b2ca 100644
--- a/lib/cpp/test/JSONProtoTest.cpp
+++ b/lib/cpp/test/JSONProtoTest.cpp
@@ -250,3 +250,22 @@ BOOST_AUTO_TEST_CASE(test_json_proto_7) {
 
   BOOST_CHECK(base == base2);
 }
+
+BOOST_AUTO_TEST_CASE(test_json_proto_8) {
+  const char* json_string =
+  
"{\"1\":{\"tf\":1},\"2\":{\"tf\":0},\"3\":{\"i8\":127},\"4\":{\"i16\":27000},"
+  
"\"5\":{\"i32\":16.77216},\"6\":{\"i64\":6000000000},\"7\":{\"dbl\":3.1415926"
+  "53589793},\"8\":{\"str\":\"JSON THIS! 
\\\"\\u0001\"},\"9\":{\"str\":\"\xd7\\"
+  
"n\\u0007\\t\"},\"10\":{\"tf\":0},\"11\":{\"str\":\"AQIDrQ\"},\"12\":{\"lst\""
+  
":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
+  "\",3,1,2,3]}}";
+
+  boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
+    (uint8_t*)(json_string), strlen(json_string)*sizeof(char)));
+  boost::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
+
+  OneOfEach ooe2;
+
+  BOOST_CHECK_THROW(ooe2.read(proto.get()),
+    apache::thrift::protocol::TProtocolException);
+}

Reply via email to