You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by br...@apache.org on 2009/09/25 22:28:36 UTC

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

Author: bryanduxbury
Date: Fri Sep 25 20:28:35 2009
New Revision: 818998

URL: http://svn.apache.org/viewvc?rev=818998&view=rev
Log:
THRIFT-588. java: Generated .equals method throws NPE for thrift object

If other is null, then they're not equal.


Modified:
    incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc
    incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/UnionTest.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=818998&r1=818997&r2=818998&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 Fri Sep 25 20:28:35 2009
@@ -951,7 +951,7 @@
   out << endl;
 
   indent(out) << "public boolean equals(" << tstruct->get_name() << " other) {" << endl;
-  indent(out) << "  return getSetField() == other.getSetField() && ((value_ instanceof byte[]) ? " << endl;
+  indent(out) << "  return other != null && getSetField() == other.getSetField() && ((value_ instanceof byte[]) ? " << endl;
   indent(out) << "    Arrays.equals((byte[])getFieldValue(), (byte[])other.getFieldValue()) : getFieldValue().equals(other.getFieldValue()));" << endl;
   indent(out) << "}" << endl;
   out << endl;

Modified: incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/UnionTest.java
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/UnionTest.java?rev=818998&r1=818997&r2=818998&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/UnionTest.java (original)
+++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/UnionTest.java Fri Sep 25 20:28:35 2009
@@ -62,6 +62,11 @@
       // sweet
     }
 
+    union = TestUnion.i32_field(1);
+    
+    if (union.equals((TestUnion)null)) {
+      throw new RuntimeException("uh oh, union.equals(null)!");
+    }
   }