diff options
author | Thomas <thomasbruggink@hotmail.com> | 2021-05-28 22:10:11 +0900 |
---|---|---|
committer | Jens Geyer <jensg@apache.org> | 2021-06-30 22:01:20 +0200 |
commit | 3c3a389c8ac546623d21e2d151c402503b358bc9 (patch) | |
tree | 48be9fb4740f1e1a8e7f1f5e81e8ea6de8bc87b9 /lib | |
parent | 5cada6a3202a0e5e11ff36dfbb925f0e037bf856 (diff) | |
download | thrift-3c3a389c8ac546623d21e2d151c402503b358bc9.tar.gz |
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java | 66 | ||||
-rw-r--r-- | lib/java/test/org/apache/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 9413f619c..38e10e19c 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 171a487ea..bc20e313f 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()); + } + } } |