You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2009/08/27 22:27:10 UTC

svn commit: r808609 - in /incubator/thrift/trunk: compiler/cpp/src/generate/t_java_generator.cc lib/java/test/org/apache/thrift/test/Fixtures.java lib/java/test/org/apache/thrift/test/TCompactProtocolTest.java

Author: dreiss
Date: Thu Aug 27 20:27:09 2009
New Revision: 808609

URL: http://svn.apache.org/viewvc?rev=808609&view=rev
Log:
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.

Modified:
    incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc
    incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/Fixtures.java
    incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/TCompactProtocolTest.java

Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc?rev=808609&r1=808608&r2=808609&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc (original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc Thu Aug 27 20:27:09 2009
@@ -1065,7 +1065,7 @@
     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 @@
   
   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 @@
           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;
         }
       }      
     }

Modified: incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/Fixtures.java
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/Fixtures.java?rev=808609&r1=808608&r2=808609&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/Fixtures.java (original)
+++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/Fixtures.java Thu Aug 27 20:27:09 2009
@@ -112,17 +112,7 @@
 
       // 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<byte[]>(compactProtoTestStruct.binary_list);
-      compactProtoTestStruct.binary_byte_map = new HashMap<byte[], Byte>() {{
-        put(new byte[]{(byte) 0, (byte) 1}, (byte) 100);
-        put(new byte[]{(byte) 2, (byte) 3}, (byte) 101);
-      }};
-      compactProtoTestStruct.byte_binary_map = new HashMap<Byte, byte[]>() {{
-        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);
     }

Modified: incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/TCompactProtocolTest.java
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/TCompactProtocolTest.java?rev=808609&r1=808608&r2=808609&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/TCompactProtocolTest.java (original)
+++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/TCompactProtocolTest.java Thu Aug 27 20:27:09 2009
@@ -324,11 +324,7 @@
     
       T objRead = klass.newInstance();
       objRead.read(proto);
-      // TODO equals is broken when List<array> 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());