diff --git a/src/google/protobuf/compiler/java/helpers.h b/src/google/protobuf/compiler/java/helpers.h index 5b2f8fd210..23d7745b5e 100644 --- a/src/google/protobuf/compiler/java/helpers.h +++ b/src/google/protobuf/compiler/java/helpers.h @@ -358,11 +358,7 @@ bool HasRequiredFields(const Descriptor* descriptor); bool IsRealOneof(const FieldDescriptor* descriptor); inline bool HasHasbit(const FieldDescriptor* descriptor) { - // TODO(b/241441075) Replace this with internal::cpp::HasHasbit once Elysium - // unblocks this change. - return (FieldDescriptorLegacy(descriptor).has_optional_keyword() || - descriptor->is_required()) && - !descriptor->options().weak(); + return internal::cpp::HasHasbit(descriptor); } // Whether generate classes expose public PARSER instances. diff --git a/src/google/protobuf/compiler/java/message_field.cc b/src/google/protobuf/compiler/java/message_field.cc index 4cb8975979..4f01843aef 100644 --- a/src/google/protobuf/compiler/java/message_field.cc +++ b/src/google/protobuf/compiler/java/message_field.cc @@ -326,8 +326,10 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( "$name$Builder_.mergeFrom(value);\n", - "$set_has_field_bit_builder$\n" - "$on_changed$\n" + "if ($name$_ != null) {\n" + " $set_has_field_bit_builder$\n" + " $on_changed$\n" + "}\n" "return this;\n", Semantic::kSet);