aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/test
diff options
context:
space:
mode:
authorNicholas Seckar <seckar@google.com>2013-09-24 20:52:54 -0700
committerUlas Kirazci <ulas@google.com>2013-10-04 10:52:08 -0700
commit37ac79028de3d1cd8c215ba54fdf31e4eeca4b2c (patch)
tree32848bf011dd0b095e8f3403366faf83387f1b4a /java/src/test
parent44dc2f1eaead8d95d3f5a4f80f9da87852053bfb (diff)
downloadexternal_protobuf-37ac79028de3d1cd8c215ba54fdf31e4eeca4b2c.zip
external_protobuf-37ac79028de3d1cd8c215ba54fdf31e4eeca4b2c.tar.gz
external_protobuf-37ac79028de3d1cd8c215ba54fdf31e4eeca4b2c.tar.bz2
Fix roundtrip failure with groups when unknown fields are enabled.
When parsing a group, the group's end tag should not be stored within the message's unknownFieldData. Not only does this waste space, it is also output the next time the group is serialized, resulting in two end tags for that group. The resulting bytes are not always a valid protocol buffer and may fail to parse. This change ensures that group end tags do not result in an unknownFieldData entry, and that messages with groups can be roundtripped without corruption. Change-Id: I240f858a7217a7652b756598c34aacad5dcc3363 Conflicts: java/src/test/java/com/google/protobuf/NanoTest.java
Diffstat (limited to 'java/src/test')
-rw-r--r--java/src/test/java/com/google/protobuf/NanoTest.java17
1 files changed, 17 insertions, 0 deletions
diff --git a/java/src/test/java/com/google/protobuf/NanoTest.java b/java/src/test/java/com/google/protobuf/NanoTest.java
index 8483619..ca0bcda 100644
--- a/java/src/test/java/com/google/protobuf/NanoTest.java
+++ b/java/src/test/java/com/google/protobuf/NanoTest.java
@@ -35,6 +35,7 @@ import com.google.protobuf.nano.EnumClassNanoMultiple;
import com.google.protobuf.nano.EnumClassNanos;
import com.google.protobuf.nano.Extensions;
import com.google.protobuf.nano.Extensions.AnotherMessage;
+import com.google.protobuf.nano.Extensions.MessageWithGroup;
import com.google.protobuf.nano.FileScopeEnumMultiple;
import com.google.protobuf.nano.FileScopeEnumRefNano;
import com.google.protobuf.nano.InternalNano;
@@ -505,6 +506,22 @@ public class NanoTest extends TestCase {
assertEquals(1, newMsg.optionalGroup.a);
}
+ public void testNanoOptionalGroupWithUnknownFieldsEnabled() throws Exception {
+ MessageWithGroup msg = new MessageWithGroup();
+ MessageWithGroup.Group grp = new MessageWithGroup.Group();
+ grp.a = 1;
+ msg.group = grp;
+ byte [] serialized = MessageNano.toByteArray(msg);
+
+ MessageWithGroup parsed = MessageWithGroup.parseFrom(serialized);
+ assertTrue(msg.group != null);
+ assertEquals(1, msg.group.a);
+
+ byte [] serialized2 = MessageNano.toByteArray(parsed);
+ assertEquals(serialized2.length, serialized.length);
+ MessageWithGroup parsed2 = MessageWithGroup.parseFrom(serialized2);
+ }
+
public void testNanoOptionalNestedMessage() throws Exception {
TestAllTypesNano msg = new TestAllTypesNano();
TestAllTypesNano.NestedMessage nestedMsg = new TestAllTypesNano.NestedMessage();