Skip to content

Commit

Permalink
THRIFT-588. java: Generated .equals method throws NPE for thrift object
Browse files Browse the repository at this point in the history
If other is null, then they're not equal.



git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@818998 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Bryan Duxbury committed Sep 25, 2009
1 parent bff2a35 commit 315a5db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/cpp/src/generate/t_java_generator.cc
Expand Up @@ -951,7 +951,7 @@ void t_java_generator::generate_union_comparisons(ofstream& out, t_struct* tstru
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;
Expand Down
5 changes: 5 additions & 0 deletions lib/java/test/org/apache/thrift/test/UnionTest.java
Expand Up @@ -62,6 +62,11 @@ public static void testBasic() throws Exception {
// sweet
}

union = TestUnion.i32_field(1);

if (union.equals((TestUnion)null)) {
throw new RuntimeException("uh oh, union.equals(null)!");
}
}


Expand Down

0 comments on commit 315a5db

Please sign in to comment.