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

jking 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 882d48d  THRIFT-4481: TBinaryProtocol.writeMessageEnd does not allow 
throwable exception
882d48d is described below

commit 882d48da5d5db439c11029f46006c71f6429ae2c
Author: Beluga Behr <dam6...@gmail.com>
AuthorDate: Thu Jan 3 09:20:16 2019 -0500

    THRIFT-4481: TBinaryProtocol.writeMessageEnd does not allow throwable 
exception
---
 .../apache/thrift/protocol/TBinaryProtocol.java    | 69 +++++++++++++++++-----
 .../apache/thrift/protocol/TCompactProtocol.java   |  2 +
 .../thrift/protocol/TSimpleJSONProtocol.java       | 59 +++++++++++++++---
 3 files changed, 107 insertions(+), 23 deletions(-)

diff --git a/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java 
b/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java
index 563128c..7924e2f 100644
--- a/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java
+++ b/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java
@@ -110,6 +110,7 @@ public class TBinaryProtocol extends TProtocol {
     strictWrite_ = strictWrite;
   }
 
+  @Override
   public void writeMessageBegin(TMessage message) throws TException {
     if (strictWrite_) {
       int version = VERSION_1 | message.type;
@@ -123,60 +124,76 @@ public class TBinaryProtocol extends TProtocol {
     }
   }
 
-  public void writeMessageEnd() {}
+  @Override
+  public void writeMessageEnd() throws TException {}
 
-  public void writeStructBegin(TStruct struct) {}
+  @Override
+  public void writeStructBegin(TStruct struct) throws TException {}
 
-  public void writeStructEnd() {}
+  @Override
+  public void writeStructEnd() throws TException {}
 
+  @Override
   public void writeFieldBegin(TField field) throws TException {
     writeByte(field.type);
     writeI16(field.id);
   }
 
-  public void writeFieldEnd() {}
+  @Override
+  public void writeFieldEnd() throws TException {}
 
+  @Override
   public void writeFieldStop() throws TException {
     writeByte(TType.STOP);
   }
 
+  @Override
   public void writeMapBegin(TMap map) throws TException {
     writeByte(map.keyType);
     writeByte(map.valueType);
     writeI32(map.size);
   }
 
-  public void writeMapEnd() {}
+  @Override
+  public void writeMapEnd() throws TException {}
 
+  @Override
   public void writeListBegin(TList list) throws TException {
     writeByte(list.elemType);
     writeI32(list.size);
   }
 
-  public void writeListEnd() {}
+  @Override
+  public void writeListEnd() throws TException {}
 
+  @Override
   public void writeSetBegin(TSet set) throws TException {
     writeByte(set.elemType);
     writeI32(set.size);
   }
 
-  public void writeSetEnd() {}
+  @Override
+  public void writeSetEnd() throws TException {}
 
+  @Override
   public void writeBool(boolean b) throws TException {
     writeByte(b ? (byte)1 : (byte)0);
   }
 
+  @Override
   public void writeByte(byte b) throws TException {
     inoutTemp[0] = b;
     trans_.write(inoutTemp, 0, 1);
   }
 
+  @Override
   public void writeI16(short i16) throws TException {
     inoutTemp[0] = (byte)(0xff & (i16 >> 8));
     inoutTemp[1] = (byte)(0xff & (i16));
     trans_.write(inoutTemp, 0, 2);
   }
 
+  @Override
   public void writeI32(int i32) throws TException {
     inoutTemp[0] = (byte)(0xff & (i32 >> 24));
     inoutTemp[1] = (byte)(0xff & (i32 >> 16));
@@ -185,6 +202,7 @@ public class TBinaryProtocol extends TProtocol {
     trans_.write(inoutTemp, 0, 4);
   }
 
+  @Override
   public void writeI64(long i64) throws TException {
     inoutTemp[0] = (byte)(0xff & (i64 >> 56));
     inoutTemp[1] = (byte)(0xff & (i64 >> 48));
@@ -197,16 +215,19 @@ public class TBinaryProtocol extends TProtocol {
     trans_.write(inoutTemp, 0, 8);
   }
 
+  @Override
   public void writeDouble(double dub) throws TException {
     writeI64(Double.doubleToLongBits(dub));
   }
 
+  @Override
   public void writeString(String str) throws TException {
     byte[] dat = str.getBytes(StandardCharsets.UTF_8);
     writeI32(dat.length);
     trans_.write(dat, 0, dat.length);
   }
 
+  @Override
   public void writeBinary(ByteBuffer bin) throws TException {
     int length = bin.limit() - bin.position();
     writeI32(length);
@@ -217,6 +238,7 @@ public class TBinaryProtocol extends TProtocol {
    * Reading methods.
    */
 
+  @Override
   public TMessage readMessageBegin() throws TException {
     int size = readI32();
     if (size < 0) {
@@ -233,50 +255,63 @@ public class TBinaryProtocol extends TProtocol {
     }
   }
 
-  public void readMessageEnd() {}
+  @Override
+  public void readMessageEnd() throws TException {}
 
-  public TStruct readStructBegin() {
+  @Override
+  public TStruct readStructBegin() throws TException {
     return ANONYMOUS_STRUCT;
   }
 
-  public void readStructEnd() {}
+  @Override
+  public void readStructEnd() throws TException {}
 
+  @Override
   public TField readFieldBegin() throws TException {
     byte type = readByte();
     short id = type == TType.STOP ? 0 : readI16();
     return new TField("", type, id);
   }
 
-  public void readFieldEnd() {}
+  @Override
+  public void readFieldEnd() throws TException {}
 
+  @Override
   public TMap readMapBegin() throws TException {
     TMap map = new TMap(readByte(), readByte(), readI32());
     checkContainerReadLength(map.size);
     return map;
   }
 
-  public void readMapEnd() {}
+  @Override
+  public void readMapEnd() throws TException {}
 
+  @Override
   public TList readListBegin() throws TException {
     TList list = new TList(readByte(), readI32());
     checkContainerReadLength(list.size);
     return list;
   }
 
-  public void readListEnd() {}
+  @Override
+  public void readListEnd() throws TException {}
 
+  @Override
   public TSet readSetBegin() throws TException {
     TSet set = new TSet(readByte(), readI32());
     checkContainerReadLength(set.size);
     return set;
   }
 
-  public void readSetEnd() {}
+  @Override
+  public void readSetEnd() throws TException {}
 
+  @Override
   public boolean readBool() throws TException {
     return (readByte() == 1);
   }
 
+  @Override
   public byte readByte() throws TException {
     if (trans_.getBytesRemainingInBuffer() >= 1) {
       byte b = trans_.getBuffer()[trans_.getBufferPosition()];
@@ -287,6 +322,7 @@ public class TBinaryProtocol extends TProtocol {
     return inoutTemp[0];
   }
 
+  @Override
   public short readI16() throws TException {
     byte[] buf = inoutTemp;
     int off = 0;
@@ -305,6 +341,7 @@ public class TBinaryProtocol extends TProtocol {
        ((buf[off+1] & 0xff)));
   }
 
+  @Override
   public int readI32() throws TException {
     byte[] buf = inoutTemp;
     int off = 0;
@@ -323,6 +360,7 @@ public class TBinaryProtocol extends TProtocol {
       ((buf[off+3] & 0xff));
   }
 
+  @Override
   public long readI64() throws TException {
     byte[] buf = inoutTemp;
     int off = 0;
@@ -346,10 +384,12 @@ public class TBinaryProtocol extends TProtocol {
       ((long)(buf[off+7] & 0xff));
   }
 
+  @Override
   public double readDouble() throws TException {
     return Double.longBitsToDouble(readI64());
   }
 
+  @Override
   public String readString() throws TException {
     int size = readI32();
 
@@ -372,6 +412,7 @@ public class TBinaryProtocol extends TProtocol {
     return new String(buf, StandardCharsets.UTF_8);
   }
 
+  @Override
   public ByteBuffer readBinary() throws TException {
     int size = readI32();
 
diff --git a/lib/java/src/org/apache/thrift/protocol/TCompactProtocol.java 
b/lib/java/src/org/apache/thrift/protocol/TCompactProtocol.java
index 92f186e..af145ef 100644
--- a/lib/java/src/org/apache/thrift/protocol/TCompactProtocol.java
+++ b/lib/java/src/org/apache/thrift/protocol/TCompactProtocol.java
@@ -203,6 +203,7 @@ public class TCompactProtocol extends TProtocol {
    * Write a message header to the wire. Compact Protocol messages contain the
    * protocol version so we can migrate forwards in the future if need be.
    */
+  @Override
   public void writeMessageBegin(TMessage message) throws TException {
     writeByteDirect(PROTOCOL_ID);
     writeByteDirect((VERSION & VERSION_MASK) | ((message.type << 
TYPE_SHIFT_AMOUNT) & TYPE_MASK));
@@ -215,6 +216,7 @@ public class TCompactProtocol extends TProtocol {
    * use it as an opportunity to put special placeholder markers on the field
    * stack so we can get the field id deltas correct.
    */
+  @Override
   public void writeStructBegin(TStruct struct) throws TException {
     lastField_.push(lastFieldId_);
     lastFieldId_ = 0;
diff --git a/lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java 
b/lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java
index e7e8d46..eb7e23b 100644
--- a/lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java
+++ b/lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java
@@ -167,6 +167,7 @@ public class TSimpleJSONProtocol extends TProtocol {
     super(trans);
   }
 
+  @Override
   public void writeMessageBegin(TMessage message) throws TException {
     resetWriteContext(); // THRIFT-3743
     trans_.write(LBRACKET);
@@ -176,31 +177,38 @@ public class TSimpleJSONProtocol extends TProtocol {
     writeI32(message.seqid);
   }
 
+  @Override
   public void writeMessageEnd() throws TException {
     popWriteContext();
     trans_.write(RBRACKET);
   }
 
+  @Override
   public void writeStructBegin(TStruct struct) throws TException {
     writeContext_.write();
     trans_.write(LBRACE);
     pushWriteContext(new StructContext());
   }
 
+  @Override
   public void writeStructEnd() throws TException {
     popWriteContext();
     trans_.write(RBRACE);
   }
 
+  @Override
   public void writeFieldBegin(TField field) throws TException {
     // Note that extra type information is omitted in JSON!
     writeString(field.name);
   }
 
-  public void writeFieldEnd() {}
+  @Override
+  public void writeFieldEnd() throws TException {}
 
-  public void writeFieldStop() {}
+  @Override
+  public void writeFieldStop() throws TException {}
 
+  @Override
   public void writeMapBegin(TMap map) throws TException {
     assertContextIsNotMapKey(MAP);
     writeContext_.write();
@@ -209,11 +217,13 @@ public class TSimpleJSONProtocol extends TProtocol {
     // No metadata!
   }
 
+  @Override
   public void writeMapEnd() throws TException {
     popWriteContext();
     trans_.write(RBRACE);
   }
 
+  @Override
   public void writeListBegin(TList list) throws TException {
     assertContextIsNotMapKey(LIST);
     writeContext_.write();
@@ -222,11 +232,13 @@ public class TSimpleJSONProtocol extends TProtocol {
     // No metadata!
   }
 
+  @Override
   public void writeListEnd() throws TException {
     popWriteContext();
     trans_.write(RBRACKET);
   }
 
+  @Override
   public void writeSetBegin(TSet set) throws TException {
     assertContextIsNotMapKey(SET);
     writeContext_.write();
@@ -235,23 +247,28 @@ public class TSimpleJSONProtocol extends TProtocol {
     // No metadata!
   }
 
+  @Override
   public void writeSetEnd() throws TException {
     popWriteContext();
     trans_.write(RBRACKET);
   }
 
+  @Override
   public void writeBool(boolean b) throws TException {
     writeByte(b ? (byte)1 : (byte)0);
   }
 
+  @Override
   public void writeByte(byte b) throws TException {
     writeI32(b);
   }
 
+  @Override
   public void writeI16(short i16) throws TException {
     writeI32(i16);
   }
 
+  @Override
   public void writeI32(int i32) throws TException {
     if(writeContext_.isMapKey()) {
       writeString(Integer.toString(i32));
@@ -266,6 +283,7 @@ public class TSimpleJSONProtocol extends TProtocol {
     trans_.write(b);
   }
 
+  @Override
   public void writeI64(long i64) throws TException {
     if(writeContext_.isMapKey()) {
       writeString(Long.toString(i64));
@@ -275,6 +293,7 @@ public class TSimpleJSONProtocol extends TProtocol {
     }
   }
 
+  @Override
   public void writeDouble(double dub) throws TException {
     if(writeContext_.isMapKey()) {
       writeString(Double.toString(dub));
@@ -284,6 +303,7 @@ public class TSimpleJSONProtocol extends TProtocol {
     }
   }
 
+  @Override
   public void writeString(String str) throws TException {
     writeContext_.write();
     int length = str.length();
@@ -337,6 +357,7 @@ public class TSimpleJSONProtocol extends TProtocol {
     _writeStringData(escape.toString());
   }
 
+  @Override
   public void writeBinary(ByteBuffer bin) throws TException {
     // TODO(mcslee): Fix this
     writeString(new String(bin.array(), bin.position() + bin.arrayOffset(),
@@ -348,77 +369,96 @@ public class TSimpleJSONProtocol extends TProtocol {
    * Reading methods.
    */
 
+  @Override
   public TMessage readMessageBegin() throws TException {
     // TODO(mcslee): implement
     return EMPTY_MESSAGE;
   }
 
-  public void readMessageEnd() {}
+  @Override
+  public void readMessageEnd() throws TException {}
 
-  public TStruct readStructBegin() {
+  @Override
+  public TStruct readStructBegin() throws TException {
     // TODO(mcslee): implement
     return ANONYMOUS_STRUCT;
   }
 
-  public void readStructEnd() {}
+  @Override
+  public void readStructEnd() throws TException {}
 
+  @Override
   public TField readFieldBegin() throws TException {
     // TODO(mcslee): implement
     return ANONYMOUS_FIELD;
   }
 
-  public void readFieldEnd() {}
+  @Override
+  public void readFieldEnd() throws TException {}
 
+  @Override
   public TMap readMapBegin() throws TException {
     // TODO(mcslee): implement
     return EMPTY_MAP;
   }
 
-  public void readMapEnd() {}
+  @Override
+  public void readMapEnd() throws TException {}
 
+  @Override
   public TList readListBegin() throws TException {
     // TODO(mcslee): implement
     return EMPTY_LIST;
   }
 
-  public void readListEnd() {}
+  @Override
+  public void readListEnd() throws TException {}
 
+  @Override
   public TSet readSetBegin() throws TException {
     // TODO(mcslee): implement
     return EMPTY_SET;
   }
 
-  public void readSetEnd() {}
+  @Override
+  public void readSetEnd() throws TException {}
 
+  @Override
   public boolean readBool() throws TException {
     return (readByte() == 1);
   }
 
+  @Override
   public byte readByte() throws TException {
     // TODO(mcslee): implement
     return 0;
   }
 
+  @Override
   public short readI16() throws TException {
     // TODO(mcslee): implement
     return 0;
   }
 
+  @Override
   public int readI32() throws TException {
     // TODO(mcslee): implement
     return 0;
   }
 
+  @Override
   public long readI64() throws TException {
     // TODO(mcslee): implement
     return 0;
   }
 
+  @Override
   public double readDouble() throws TException {
     // TODO(mcslee): implement
     return 0;
   }
 
+  @Override
   public String readString() throws TException {
     // TODO(mcslee): implement
     return "";
@@ -429,6 +469,7 @@ public class TSimpleJSONProtocol extends TProtocol {
     return "";
   }
 
+  @Override
   public ByteBuffer readBinary() throws TException {
     // TODO(mcslee): implement
     return ByteBuffer.wrap(new byte[0]);

Reply via email to