Skip to content

Commit

Permalink
(bugfix) fix getMessage generation for @thrift.ErrorMessage in Java
Browse files Browse the repository at this point in the history
Summary: D50940922 introduced `thrift.ErrorMessage`, but it contains a small bug where java error message may be swallowed. in this diff, we fixed this bug.

Reviewed By: prakashgayasen, thedavekwon

Differential Revision: D51224128

fbshipit-source-id: 84d1f4553d6f2f645c7be54c16daf5a0ee32e261
  • Loading branch information
avalonalex authored and facebook-github-bot committed Nov 13, 2023
1 parent dcc8c61 commit f8b40a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 7 additions & 4 deletions thrift/compiler/generate/t_mstch_java_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,14 @@ class mstch_java_struct : public mstch_struct {
return get_java_swift_name(message_field);
}
// we can only override Throwable's getMessage() if:
// 1 - there is provided 'message' annotation
// 2 - there is no struct field named 'message'
// (since it will generate getMessage() as well)
// 1 - there is either provided `'message'` annotation or
// `@thrift.ErrorMessage` annotation.
// 2 - there is no struct field named 'message' (since it
// will generate `getMessage()` method)
mstch::node needs_exception_message() {
return struct_->is_exception() && struct_->has_annotation("message") &&
return struct_->is_exception() &&
dynamic_cast<const t_exception&>(*struct_).get_message_field() !=
nullptr &&
struct_->get_field_by_name("message") == nullptr;
}
};
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f8b40a0

Please sign in to comment.