From af81de0123c8d9920a25a27d28da66f9d00748cc Mon Sep 17 00:00:00 2001 From: David Reiss Date: Thu, 27 Aug 2009 20:27:09 +0000 Subject: [PATCH] Revert r806014 "THRIFT-562. java: Java is inconsistent ..." - It changed the semantics of default-presence fields. - It messed up calls that accept exceptions. - Full details on issue. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@808609 13f79535-47bb-0310-9956-ffa450edef68 --- compiler/cpp/src/generate/t_java_generator.cc | 6 +++--- lib/java/test/org/apache/thrift/test/Fixtures.java | 12 +----------- .../org/apache/thrift/test/TCompactProtocolTest.java | 6 +----- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc index 0a6ebead..32e9b54d 100644 --- a/compiler/cpp/src/generate/t_java_generator.cc +++ b/compiler/cpp/src/generate/t_java_generator.cc @@ -1065,7 +1065,7 @@ void t_java_generator::generate_java_struct_reader(ofstream& out, if (!bean_style_){ out << endl << indent() << "// check for required fields of primitive type, which can't be checked in the validate method" << endl; for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) { - if ((*f_iter)->get_req() != t_field::T_OPTIONAL && !type_can_be_null((*f_iter)->get_type())) { + if ((*f_iter)->get_req() == t_field::T_REQUIRED && !type_can_be_null((*f_iter)->get_type())) { out << indent() << "if (!" << generate_isset_check(*f_iter) << ") {" << endl << indent() << " throw new TProtocolException(\"Required field '" << (*f_iter)->get_name() << "' was not found in serialized data! Struct: \" + toString());" << endl << @@ -1095,7 +1095,7 @@ void t_java_generator::generate_java_validator(ofstream& out, out << indent() << "// check for required fields" << endl; for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) { - if ((*f_iter)->get_req() != t_field::T_OPTIONAL) { + if ((*f_iter)->get_req() == t_field::T_REQUIRED) { if (bean_style_) { out << indent() << "if (!" << generate_isset_check(*f_iter) << ") {" << endl << @@ -1107,7 +1107,7 @@ void t_java_generator::generate_java_validator(ofstream& out, indent(out) << " throw new TProtocolException(\"Required field '" << (*f_iter)->get_name() << "' was not present! Struct: \" + toString());" << endl; indent(out) << "}" << endl; } else { - indent(out) << "// '" << (*f_iter)->get_name() << "' is only checked in read() because it's a primitive and you chose the non-beans generator." << endl; + indent(out) << "// alas, we cannot check '" << (*f_iter)->get_name() << "' because it's a primitive and you chose the non-beans generator." << endl; } } } diff --git a/lib/java/test/org/apache/thrift/test/Fixtures.java b/lib/java/test/org/apache/thrift/test/Fixtures.java index 7ef91ef2..ea250dd9 100644 --- a/lib/java/test/org/apache/thrift/test/Fixtures.java +++ b/lib/java/test/org/apache/thrift/test/Fixtures.java @@ -112,17 +112,7 @@ public class Fixtures { // superhuge compact proto test struct compactProtoTestStruct = new CompactProtoTestStruct(thrift.test.Constants.COMPACT_TEST); - compactProtoTestStruct.a_binary = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8}; - compactProtoTestStruct.binary_list = Arrays.asList(new byte[]{(byte) 0, (byte) 1}, new byte[]{(byte) 2, (byte) 3}); - compactProtoTestStruct.binary_set = new HashSet(compactProtoTestStruct.binary_list); - compactProtoTestStruct.binary_byte_map = new HashMap() {{ - put(new byte[]{(byte) 0, (byte) 1}, (byte) 100); - put(new byte[]{(byte) 2, (byte) 3}, (byte) 101); - }}; - compactProtoTestStruct.byte_binary_map = new HashMap() {{ - put((byte) 100, new byte[]{(byte) 0, (byte) 1}); - put((byte) 101, new byte[]{(byte) 2, (byte) 3}); - }}; + compactProtoTestStruct.a_binary = new byte[]{0,1,2,3,4,5,6,7,8}; } catch (Exception e) { throw new RuntimeException(e); } diff --git a/lib/java/test/org/apache/thrift/test/TCompactProtocolTest.java b/lib/java/test/org/apache/thrift/test/TCompactProtocolTest.java index 99173401..5d1c3cba 100755 --- a/lib/java/test/org/apache/thrift/test/TCompactProtocolTest.java +++ b/lib/java/test/org/apache/thrift/test/TCompactProtocolTest.java @@ -324,11 +324,7 @@ public class TCompactProtocolTest { T objRead = klass.newInstance(); objRead.read(proto); - // TODO equals is broken when List is involved, since AbstractList.equals(Object o) - // calls o.equals, but for arrays that is just == which will never work when you are - // comparing pre- and post- serialized versions. You need to use Arrays.equals instead. - // So, here I have special-cased CPTS to avoid failing the test b/c of this bug. - if (!obj.equals(objRead) && klass != CompactProtoTestStruct.class) { + if (!obj.equals(objRead)) { System.out.println("Expected: " + obj.toString()); System.out.println("Actual: " + objRead.toString()); // System.out.println(buf.inspect()); -- 2.17.1