protobuf: fix a data race in AbstractProtobufList

Unconditional update of isMutable causes data races for
LazyStringArrayList::EMPTY_LIST that is used as the default value
for protobuf fields.

Not writing to it unconditionally may also improve performance
by reducing contention for the presumably widely shared EMPTY_LIST object.

PiperOrigin-RevId: 510366298
pull/11977/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent d41deb9dc6
commit 6d776dfed5
  1. 4
      java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java

@ -130,7 +130,9 @@ abstract class AbstractProtobufList<E> extends AbstractList<E> implements Protob
@Override @Override
public final void makeImmutable() { public final void makeImmutable() {
isMutable = false; if (isMutable) {
isMutable = false;
}
} }
@Override @Override

Loading…
Cancel
Save