File tree 1 file changed +6
-1
lines changed
java/core/src/main/java/com/google/protobuf 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -407,8 +407,13 @@ Object buildMessageInfo() throws Exception {
407
407
408
408
protected static <T extends GeneratedMessageLite <?, ?>> void registerDefaultInstance (
409
409
Class <T > clazz , T defaultInstance ) {
410
+ // Default instances must be immutable.
411
+ // Marking immutable here to avoid extra bytecode in every generated message class.
412
+ // Only calling "markImmutable" rather than "makeImmutable" because for Default Instances:
413
+ // 1. All sub-messages are initialized to null / default instances and thus immutable
414
+ // 2. All lists are initialized to default instance empty lists which are also immutable.
415
+ defaultInstance .markImmutable ();
410
416
defaultInstanceMap .put (clazz , defaultInstance );
411
- defaultInstance .makeImmutable ();
412
417
}
413
418
414
419
protected static Object newMessageInfo (
You can’t perform that action at this time.
0 commit comments