From 85bbceea819089945eeeb3e310a0f97d312598fb Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 29 Oct 2024 00:47:09 -0700 Subject: [PATCH] Internal Change PiperOrigin-RevId: 690909150 --- .../google/protobuf/GeneratedMessageLite.java | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java index dfa146b19eb27..4e35c06e70470 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java @@ -496,24 +496,20 @@ public BuilderType mergeFrom(MessageType message) { return (BuilderType) this; } - private static void mergeFromInstance(MessageType dest, MessageType src) { - Protobuf.getInstance().schemaFor(dest).mergeFrom(dest, src); - } - - @Override - public MessageType getDefaultInstanceForType() { - return defaultInstance; - } - @Override public BuilderType mergeFrom( byte[] input, int offset, int length, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { copyOnWrite(); try { - Protobuf.getInstance().schemaFor(instance).mergeFrom( - instance, input, offset, offset + length, - new ArrayDecoders.Registers(extensionRegistry)); + Protobuf.getInstance() + .schemaFor(instance) + .mergeFrom( + instance, + input, + offset, + offset + length, + new ArrayDecoders.Registers(extensionRegistry)); } catch (InvalidProtocolBufferException e) { throw e; } catch (IndexOutOfBoundsException e) { @@ -525,8 +521,7 @@ public BuilderType mergeFrom( } @Override - public BuilderType mergeFrom( - byte[] input, int offset, int length) + public BuilderType mergeFrom(byte[] input, int offset, int length) throws InvalidProtocolBufferException { return mergeFrom(input, offset, length, ExtensionRegistryLite.getEmptyRegistry()); } @@ -540,8 +535,9 @@ public BuilderType mergeFrom( try { // TODO: Try to make input with type CodedInputStream.ArrayDecoder use // fast path. - Protobuf.getInstance().schemaFor(instance).mergeFrom( - instance, CodedInputStreamReader.forCodedInput(input), extensionRegistry); + Protobuf.getInstance() + .schemaFor(instance) + .mergeFrom(instance, CodedInputStreamReader.forCodedInput(input), extensionRegistry); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); @@ -550,6 +546,15 @@ public BuilderType mergeFrom( } return (BuilderType) this; } + + private static void mergeFromInstance(MessageType dest, MessageType src) { + Protobuf.getInstance().schemaFor(dest).mergeFrom(dest, src); + } + + @Override + public MessageType getDefaultInstanceForType() { + return defaultInstance; + } } // ================================================================= @@ -667,7 +672,7 @@ private boolean parseExtension( while (input.getBytesUntilLimit() > 0) { Object value = FieldSet.readPrimitiveField( - input, extension.descriptor.getLiteType(), /*checkUtf8=*/ false); + input, extension.descriptor.getLiteType(), /* checkUtf8= */ false); extensions.addRepeatedField(extension.descriptor, value); } } @@ -708,7 +713,7 @@ private boolean parseExtension( default: value = FieldSet.readPrimitiveField( - input, extension.descriptor.getLiteType(), /*checkUtf8=*/ false); + input, extension.descriptor.getLiteType(), /* checkUtf8= */ false); break; } @@ -1422,8 +1427,10 @@ protected Object readResolve() throws ObjectStreamException { java.lang.reflect.Field defaultInstanceField = messageClass.getDeclaredField("DEFAULT_INSTANCE"); defaultInstanceField.setAccessible(true); - MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(null); - return defaultInstance.newBuilderForType().mergeFrom(asBytes).buildPartial(); + MessageLite.Builder builder = + ((MessageLite) defaultInstanceField.get(null)).newBuilderForType(); + builder.mergeFrom(asBytes); + return builder.buildPartial(); } catch (ClassNotFoundException e) { throw new RuntimeException("Unable to find proto buffer class: " + messageClassName, e); } catch (NoSuchFieldException e) { @@ -1698,8 +1705,9 @@ public T parsePartialFrom( // Validates last tag. protected static > T parseFrom( T defaultInstance, byte[] data) throws InvalidProtocolBufferException { - return checkMessageInitialized(parsePartialFrom( - defaultInstance, data, 0, data.length, ExtensionRegistryLite.getEmptyRegistry())); + return checkMessageInitialized( + parsePartialFrom( + defaultInstance, data, 0, data.length, ExtensionRegistryLite.getEmptyRegistry())); } // Validates last tag.