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. 2
      java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java

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

Loading…
Cancel
Save