aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/test/java/com/google/protobuf/NanoTest.java
diff options
context:
space:
mode:
authorDave Hawkey <dhawkey@google.com>2014-03-20 10:55:41 -0600
committerDave Hawkey <dhawkey@google.com>2014-04-10 08:21:44 -0600
commitc82101204dcde798f870d95e91f5483c3e57eb29 (patch)
tree377a25f535ffb0e37a1762f2d3b7b1ca83a4ece1 /java/src/test/java/com/google/protobuf/NanoTest.java
parentce2f59915e0b41c935e3f72a2b7b71b6c19b6860 (diff)
downloadexternal_protobuf-c82101204dcde798f870d95e91f5483c3e57eb29.zip
external_protobuf-c82101204dcde798f870d95e91f5483c3e57eb29.tar.gz
external_protobuf-c82101204dcde798f870d95e91f5483c3e57eb29.tar.bz2
Don't reset cachedSize to 0 in getSerializedSize
This avoids a race-condition when cachedSize is momentarily set to 0 for non-empty messages if multiple threads call getSerializedSize (e.g. during serialization). This is a retry of https://android-review.googlesource.com/#/c/88570/. getSerializedSize() has been kept non-final so that messages generated with a previous version of the compiler will not break. Change-Id: I8d8154a10938cde579ae19c55eae55b1e70e0bda
Diffstat (limited to 'java/src/test/java/com/google/protobuf/NanoTest.java')
-rw-r--r--java/src/test/java/com/google/protobuf/NanoTest.java12
1 files changed, 12 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 9987cac..5f28647 100644
--- a/java/src/test/java/com/google/protobuf/NanoTest.java
+++ b/java/src/test/java/com/google/protobuf/NanoTest.java
@@ -105,6 +105,12 @@ public class NanoTest extends TestCase {
assertEquals(456, newMsg.d);
assertEquals(2, msg.nestedMsg.bb);
assertEquals(SimpleMessageNano.BAR, msg.defaultNestedEnum);
+
+ msg.nestedMsg = null;
+ assertTrue(msgSerializedSize != msg.getSerializedSize());
+
+ msg.clear();
+ assertEquals(0, msg.getSerializedSize());
}
public void testRecursiveMessageNano() throws Exception {
@@ -143,6 +149,12 @@ public class NanoTest extends TestCase {
assertEquals(3, newMsg.repeatedRecursiveMessageNano[0].id);
}
+ public void testMessageNoFields() {
+ SingleMessageNano msg = new SingleMessageNano();
+ assertEquals(0, msg.getSerializedSize());
+ assertEquals(0, MessageNano.toByteArray(msg).length);
+ }
+
public void testNanoRequiredInt32() throws Exception {
TestAllTypesNano msg = new TestAllTypesNano();
msg.id = 123;