You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2021/06/30 20:01:52 UTC

[thrift] branch master updated: THRIFT-5425 Throw an exception when reading TSimpleJson in Java Client: java Author: Thomas Bruggink

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

jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new 3c3a389  THRIFT-5425 Throw an exception when reading TSimpleJson in Java Client: java Author: Thomas Bruggink
3c3a389 is described below

commit 3c3a389c8ac546623d21e2d151c402503b358bc9
Author: Thomas <th...@hotmail.com>
AuthorDate: Fri May 28 22:10:11 2021 +0900

    THRIFT-5425 Throw an exception when reading TSimpleJson in Java
    Client: java
    Author: Thomas Bruggink
    
    This closes #2400
    
    Throw an exception when reading TSimpleJson and update the comment to explain why.
---
 .../thrift/protocol/TSimpleJSONProtocol.java       | 66 ++++++++++------------
 .../thrift/protocol/TestTSimpleJSONProtocol.java   | 13 +++++
 2 files changed, 44 insertions(+), 35 deletions(-)

diff --git a/lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java b/lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java
index 9413f61..38e10e1 100644
--- a/lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java
+++ b/lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java
@@ -368,112 +368,108 @@ public class TSimpleJSONProtocol extends TProtocol {
 
   /**
    * Reading methods.
+   *
+   * simplejson is not meant to be read back into thrift
+   * - see http://wiki.apache.org/thrift/ThriftUsageJava
+   * - use JSON instead
    */
 
   @Override
   public TMessage readMessageBegin() throws TException {
-    // TODO(mcslee): implement
-    return EMPTY_MESSAGE;
+    throw new TException("Not implemented");
   }
 
   @Override
-  public void readMessageEnd() throws TException {}
+  public void readMessageEnd() throws TException {
+    throw new TException("Not implemented");}
 
   @Override
   public TStruct readStructBegin() throws TException {
-    // TODO(mcslee): implement
-    return ANONYMOUS_STRUCT;
+    throw new TException("Not implemented");
   }
 
   @Override
-  public void readStructEnd() throws TException {}
+  public void readStructEnd() throws TException {
+    throw new TException("Not implemented");}
 
   @Override
   public TField readFieldBegin() throws TException {
-    // TODO(mcslee): implement
-    return ANONYMOUS_FIELD;
+    throw new TException("Not implemented");
   }
 
   @Override
-  public void readFieldEnd() throws TException {}
+  public void readFieldEnd() throws TException {
+    throw new TException("Not implemented");}
 
   @Override
   public TMap readMapBegin() throws TException {
-    // TODO(mcslee): implement
-    return EMPTY_MAP;
+    throw new TException("Not implemented");
   }
 
   @Override
-  public void readMapEnd() throws TException {}
+  public void readMapEnd() throws TException {
+    throw new TException("Not implemented");}
 
   @Override
   public TList readListBegin() throws TException {
-    // TODO(mcslee): implement
-    return EMPTY_LIST;
+    throw new TException("Not implemented");
   }
 
   @Override
-  public void readListEnd() throws TException {}
+  public void readListEnd() throws TException {
+    throw new TException("Not implemented");}
 
   @Override
   public TSet readSetBegin() throws TException {
-    // TODO(mcslee): implement
-    return EMPTY_SET;
+    throw new TException("Not implemented");
   }
 
   @Override
-  public void readSetEnd() throws TException {}
+  public void readSetEnd() throws TException {
+    throw new TException("Not implemented");}
 
   @Override
   public boolean readBool() throws TException {
-    return (readByte() == 1);
+    throw new TException("Not implemented");
   }
 
   @Override
   public byte readByte() throws TException {
-    // TODO(mcslee): implement
-    return 0;
+    throw new TException("Not implemented");
   }
 
   @Override
   public short readI16() throws TException {
-    // TODO(mcslee): implement
-    return 0;
+    throw new TException("Not implemented");
   }
 
   @Override
   public int readI32() throws TException {
-    // TODO(mcslee): implement
-    return 0;
+    throw new TException("Not implemented");
   }
 
   @Override
   public long readI64() throws TException {
-    // TODO(mcslee): implement
-    return 0;
+    throw new TException("Not implemented");
   }
 
   @Override
   public double readDouble() throws TException {
-    // TODO(mcslee): implement
-    return 0;
+    throw new TException("Not implemented");
   }
 
   @Override
   public String readString() throws TException {
-    // TODO(mcslee): implement
-    return "";
+    throw new TException("Not implemented");
   }
 
   public String readStringBody(int size) throws TException {
-    // TODO(mcslee): implement
-    return "";
+    throw new TException("Not implemented");
   }
 
   @Override
   public ByteBuffer readBinary() throws TException {
-    // TODO(mcslee): implement
-    return ByteBuffer.wrap(new byte[0]);
+    throw new TException("Not implemented");
   }
 
   public static class CollectionMapKeyException extends TException {
diff --git a/lib/java/test/org/apache/thrift/protocol/TestTSimpleJSONProtocol.java b/lib/java/test/org/apache/thrift/protocol/TestTSimpleJSONProtocol.java
index 171a487..bc20e31 100644
--- a/lib/java/test/org/apache/thrift/protocol/TestTSimpleJSONProtocol.java
+++ b/lib/java/test/org/apache/thrift/protocol/TestTSimpleJSONProtocol.java
@@ -23,9 +23,11 @@ import java.nio.charset.StandardCharsets;
 import junit.framework.TestCase;
 
 import org.apache.thrift.Fixtures;
+import org.apache.thrift.TDeserializer;
 import org.apache.thrift.TException;
 import org.apache.thrift.transport.TMemoryBuffer;
 
+import org.apache.thrift.transport.TTransportException;
 import thrift.test.CompactProtoTestStruct;
 import thrift.test.HolyMoley;
 
@@ -91,4 +93,15 @@ public class TestTSimpleJSONProtocol extends TestCase {
       //
     }
   }
+
+  public void testReadingThrows() throws TTransportException {
+    String input = "{\"test\": \"value\"}";
+    TDeserializer deserializer = new TDeserializer(new TSimpleJSONProtocol.Factory());
+    try {
+      deserializer.fromString(Fixtures.oneOfEach, input);
+      fail("Was able to read SimpleJSON");
+    } catch (TException e) {
+      assertEquals("Not implemented", e.getMessage());
+    }
+  }
 }