summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorBrian Duff <bduff@google.com>2015-01-09 13:32:38 -0800
committerBrian Duff <bduff@google.com>2015-01-09 13:32:38 -0800
commit5537d6fe4af105eb769bacc530e8d5d9e0b027cb (patch)
tree798a5b61c9daded298fdbd60d567f88fade89ada /java
parentc35945d022afb86631adfc746254598c60323f72 (diff)
downloadexternal_protobuf-5537d6fe4af105eb769bacc530e8d5d9e0b027cb.zip
external_protobuf-5537d6fe4af105eb769bacc530e8d5d9e0b027cb.tar.gz
external_protobuf-5537d6fe4af105eb769bacc530e8d5d9e0b027cb.tar.bz2
When no clear() is generated, still initialize fields.
https://android-review.googlesource.com/#/c/67890/ removed field initialization from the ctor, making it just call clear() instead. When I added the generate_clear option back (as part of the reftypes compat mode) in https://android-review.googlesource.com/#/c/109530/, I forgot to ensure that what clear() used to do was inlined in the constructor. This change fixes NPEs that are happening for users of reftypes_compat_mode who rely on unset repeated fields being empty arrays rather than null. Change-Id: Idb58746c60f4a4054b7ebb5c3b0e76b16ff88184
Diffstat (limited to 'java')
-rw-r--r--java/pom.xml6
-rw-r--r--java/src/test/java/com/google/protobuf/NanoTest.java6
2 files changed, 12 insertions, 0 deletions
diff --git a/java/pom.xml b/java/pom.xml
index d263bec..1f110d9 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -211,6 +211,12 @@
<arg value="--proto_path=src/test/java" />
<arg value="../src/google/protobuf/unittest_reference_types_nano.proto" />
</exec>
+ <exec executable="../src/protoc">
+ <arg value="--javanano_out=optional_field_style=reftypes_compat_mode,generate_equals=true,java_outer_classname=google/protobuf/unittest_reference_types_nano.proto|NanoReferenceTypesCompat:target/generated-test-sources" />
+ <arg value="--proto_path=../src" />
+ <arg value="--proto_path=src/test/java" />
+ <arg value="../src/google/protobuf/unittest_reference_types_nano.proto" />
+ </exec>
</tasks>
<testSourceRoot>target/generated-test-sources</testSourceRoot>
<!--testSourceRoot>target/generated-test-sources/opt-space</testSourceRoot-->
diff --git a/java/src/test/java/com/google/protobuf/NanoTest.java b/java/src/test/java/com/google/protobuf/NanoTest.java
index aa555c8..81e57c0 100644
--- a/java/src/test/java/com/google/protobuf/NanoTest.java
+++ b/java/src/test/java/com/google/protobuf/NanoTest.java
@@ -49,6 +49,7 @@ import com.google.protobuf.nano.NanoHasOuterClass.TestAllTypesNanoHas;
import com.google.protobuf.nano.NanoOuterClass;
import com.google.protobuf.nano.NanoOuterClass.TestAllTypesNano;
import com.google.protobuf.nano.NanoReferenceTypes;
+import com.google.protobuf.nano.NanoReferenceTypesCompat;
import com.google.protobuf.nano.NanoRepeatedPackables;
import com.google.protobuf.nano.PackedExtensions;
import com.google.protobuf.nano.RepeatedExtensions;
@@ -3789,6 +3790,11 @@ public class NanoTest extends TestCase {
assertTrue(Arrays.equals(new boolean[] {false, true, false, true}, nonPacked.bools));
}
+ public void testRepeatedFieldInitializedInReftypesCompatMode() {
+ NanoReferenceTypesCompat.TestAllTypesNano proto = new NanoReferenceTypesCompat.TestAllTypesNano();
+ assertNotNull(proto.repeatedString);
+ }
+
private void assertRepeatedPackablesEqual(
NanoRepeatedPackables.NonPacked nonPacked, NanoRepeatedPackables.Packed packed) {
// Not using MessageNano.equals() -- that belongs to a separate test.