Skip to content

Commit

Permalink
Merge pull request #10770 from protocolbuffers/googleberg-cl-480629524
Browse files Browse the repository at this point in the history
Mark default instance as immutable first to avoid race during static initialization of default instances.
  • Loading branch information
googleberg committed Oct 13, 2022
1 parent 5d90ef2 commit 1594ac1
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,13 @@ Object buildMessageInfo() throws Exception {

protected static <T extends GeneratedMessageLite<?, ?>> void registerDefaultInstance(
Class<T> clazz, T defaultInstance) {
// Default instances must be immutable.
// Marking immutable here to avoid extra bytecode in every generated message class.
// Only calling "markImmutable" rather than "makeImmutable" because for Default Instances:
// 1. All sub-messages are initialized to null / default instances and thus immutable
// 2. All lists are initialized to default instance empty lists which are also immutable.
defaultInstance.markImmutable();
defaultInstanceMap.put(clazz, defaultInstance);
defaultInstance.makeImmutable();
}

protected static Object newMessageInfo(
Expand Down

0 comments on commit 1594ac1

Please sign in to comment.