Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion compiler/cpp/src/thrift/generate/t_java_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class t_java_generator : public t_oop_generator {
std::string generate_isset_check(t_field* field);
std::string generate_isset_check(std::string field);
void generate_isset_set(ostream& out, t_field* field, std::string prefix);
void generate_isset_set_in_constructor(ostream& out, t_struct* tstruct, t_field* field);
std::string isset_field_id(t_field* field);

void generate_service_interface(t_service* tservice);
Expand Down Expand Up @@ -1698,7 +1699,7 @@ void t_java_generator::generate_java_struct_definition(ostream& out,
<< make_valid_java_identifier((*m_iter)->get_name()) << ";"
<< '\n';
}
generate_isset_set(out, (*m_iter), "");
generate_isset_set_in_constructor(out, tstruct, *m_iter);
}
}

Expand Down Expand Up @@ -5260,6 +5261,30 @@ void t_java_generator::generate_isset_set(ostream& out, t_field* field, string p
}
}

/**
* Marks a field as set from a constructor. Calling the public, overridable setXIsSet() there
* lets 'this' escape before a subclass is initialized (javac's this-escape lint), so the bit is
* set directly, the way that method does it.
*/
void t_java_generator::generate_isset_set_in_constructor(ostream& out,
t_struct* tstruct,
t_field* field) {
if (type_can_be_null(field->get_type())) {
return;
}
switch (needs_isset(tstruct)) {
case ISSET_PRIMITIVE:
indent(out) << "__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, "
<< isset_field_id(field) << ", true);" << '\n';
break;
case ISSET_BITSET:
indent(out) << "__isset_bit_vector.set(" << isset_field_id(field) << ", true);" << '\n';
break;
case ISSET_NONE:
break;
}
}

void t_java_generator::generate_struct_desc(ostream& out, t_struct* tstruct) {
indent(out) << "private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new "
"org.apache.thrift.protocol.TStruct(\""
Expand Down
Loading