summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Cai <maxtroy@google.com>2014-08-21 17:39:00 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-08-21 17:39:00 +0000
commitc6d612ac7b18ba758c9067136c1217589aa5796f (patch)
treea21d25a6db12a86353e7bc88a5e3a43c3e0ecccd
parentb172d66772c921589a1338f00b34ff5bc3bcc225 (diff)
parentecb2c88b22ad898c088a81870f58adbf4e16d126 (diff)
downloadexternal_protobuf-c6d612ac7b18ba758c9067136c1217589aa5796f.zip
external_protobuf-c6d612ac7b18ba758c9067136c1217589aa5796f.tar.gz
external_protobuf-c6d612ac7b18ba758c9067136c1217589aa5796f.tar.bz2
* commit 'ecb2c88b22ad898c088a81870f58adbf4e16d126': Fix access around unknownFieldData.
-rw-r--r--java/pom.xml2
-rw-r--r--java/src/device/test/java/com/google/protobuf/nano/NanoAndroidTest.java4
-rw-r--r--java/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java25
-rw-r--r--java/src/test/java/com/google/protobuf/NanoTest.java8
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_message.cc9
-rw-r--r--src/google/protobuf/unittest_extension_nano.proto2
-rw-r--r--src/google/protobuf/unittest_import_nano.proto2
7 files changed, 36 insertions, 16 deletions
diff --git a/java/pom.xml b/java/pom.xml
index 0a29f31..d263bec 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -134,7 +134,7 @@
<!-- java nano -->
<exec executable="../src/protoc">
<arg value="--javanano_out=
- java_package = google/protobuf/unittest_import_nano.proto|com.google.protobuf.nano,
+ java_package = google/protobuf/unittest_import_nano.proto|com.google.protobuf.nano.testimport,
java_outer_classname = google/protobuf/unittest_import_nano.proto|UnittestImportNano,
generate_equals = true
:target/generated-test-sources" />
diff --git a/java/src/device/test/java/com/google/protobuf/nano/NanoAndroidTest.java b/java/src/device/test/java/com/google/protobuf/nano/NanoAndroidTest.java
index 7092485..4b53607 100644
--- a/java/src/device/test/java/com/google/protobuf/nano/NanoAndroidTest.java
+++ b/java/src/device/test/java/com/google/protobuf/nano/NanoAndroidTest.java
@@ -32,10 +32,10 @@ package com.google.protobuf.nano;
import android.os.Parcel;
-import com.google.protobuf.nano.Extensions.ContainerMessage;
-import com.google.protobuf.nano.Extensions.ExtendableMessage;
import com.google.protobuf.nano.UnittestSimpleNano.SimpleMessageNano;
import com.google.protobuf.nano.UnittestSimpleNano.SimpleMessageNano.NestedMessage;
+import com.google.protobuf.nano.testext.Extensions.ContainerMessage;
+import com.google.protobuf.nano.testext.Extensions.ExtendableMessage;
import junit.framework.TestCase;
diff --git a/java/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java b/java/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java
index a0c2731..5984d35 100644
--- a/java/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java
+++ b/java/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java
@@ -147,4 +147,29 @@ public abstract class ExtendableMessageNano<M extends ExtendableMessageNano<M>>
field.addUnknownField(unknownField);
return true;
}
+
+ /**
+ * Returns whether the stored unknown field data in this message is equivalent to that in the
+ * other message.
+ *
+ * @param other the other message.
+ * @return whether the two sets of unknown field data are equal.
+ */
+ protected final boolean unknownFieldDataEquals(M other) {
+ if (unknownFieldData == null || unknownFieldData.isEmpty()) {
+ return other.unknownFieldData == null || other.unknownFieldData.isEmpty();
+ } else {
+ return unknownFieldData.equals(other.unknownFieldData);
+ }
+ }
+
+ /**
+ * Computes the hashcode representing the unknown field data stored in this message.
+ *
+ * @return the hashcode for the unknown field data.
+ */
+ protected final int unknownFieldDataHashCode() {
+ return (unknownFieldData == null || unknownFieldData.isEmpty()
+ ? 0 : unknownFieldData.hashCode());
+ }
}
diff --git a/java/src/test/java/com/google/protobuf/NanoTest.java b/java/src/test/java/com/google/protobuf/NanoTest.java
index 93c9dc4..e831c52 100644
--- a/java/src/test/java/com/google/protobuf/NanoTest.java
+++ b/java/src/test/java/com/google/protobuf/NanoTest.java
@@ -35,9 +35,6 @@ import com.google.protobuf.nano.EnumClassNanoMultiple;
import com.google.protobuf.nano.EnumClassNanos;
import com.google.protobuf.nano.EnumValidity;
import com.google.protobuf.nano.EnumValidityAccessors;
-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;
@@ -57,11 +54,14 @@ import com.google.protobuf.nano.PackedExtensions;
import com.google.protobuf.nano.RepeatedExtensions;
import com.google.protobuf.nano.SingularExtensions;
import com.google.protobuf.nano.TestRepeatedMergeNano;
-import com.google.protobuf.nano.UnittestImportNano;
import com.google.protobuf.nano.UnittestMultipleNano;
import com.google.protobuf.nano.UnittestRecursiveNano.RecursiveMessageNano;
import com.google.protobuf.nano.UnittestSimpleNano.SimpleMessageNano;
import com.google.protobuf.nano.UnittestSingleNano.SingleMessageNano;
+import com.google.protobuf.nano.testext.Extensions;
+import com.google.protobuf.nano.testext.Extensions.AnotherMessage;
+import com.google.protobuf.nano.testext.Extensions.MessageWithGroup;
+import com.google.protobuf.nano.testimport.UnittestImportNano;
import junit.framework.TestCase;
diff --git a/src/google/protobuf/compiler/javanano/javanano_message.cc b/src/google/protobuf/compiler/javanano/javanano_message.cc
index 0cf9f97..7a2b4a0 100644
--- a/src/google/protobuf/compiler/javanano/javanano_message.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_message.cc
@@ -501,11 +501,7 @@ void MessageGenerator::GenerateEquals(io::Printer* printer) {
if (params_.store_unknown_fields()) {
printer->Print(
- "if (unknownFieldData == null || unknownFieldData.isEmpty()) {\n"
- " return other.unknownFieldData == null || other.unknownFieldData.isEmpty();"
- "} else {\n"
- " return unknownFieldData.equals(other.unknownFieldData);\n"
- "}\n");
+ "return unknownFieldDataEquals(other);\n");
} else {
printer->Print(
"return true;\n");
@@ -534,8 +530,7 @@ void MessageGenerator::GenerateHashCode(io::Printer* printer) {
if (params_.store_unknown_fields()) {
printer->Print(
- "result = 31 * result + (unknownFieldData == null || unknownFieldData.isEmpty()\n"
- " ? 0 : unknownFieldData.hashCode());\n");
+ "result = 31 * result + unknownFieldDataHashCode();\n");
}
printer->Print("return result;\n");
diff --git a/src/google/protobuf/unittest_extension_nano.proto b/src/google/protobuf/unittest_extension_nano.proto
index 0a775f4..2a678a8 100644
--- a/src/google/protobuf/unittest_extension_nano.proto
+++ b/src/google/protobuf/unittest_extension_nano.proto
@@ -1,7 +1,7 @@
syntax = "proto2";
option java_outer_classname = "Extensions";
-option java_package = "com.google.protobuf.nano";
+option java_package = "com.google.protobuf.nano.testext";
message ExtendableMessage {
optional int32 field = 1;
diff --git a/src/google/protobuf/unittest_import_nano.proto b/src/google/protobuf/unittest_import_nano.proto
index 7813715..0a2fde7 100644
--- a/src/google/protobuf/unittest_import_nano.proto
+++ b/src/google/protobuf/unittest_import_nano.proto
@@ -35,7 +35,7 @@
package protobuf_unittest_import;
// java_package and java_outer_classname are specified on the command line.
-//option java_package = "com.google.protobuf.nano";
+//option java_package = "com.google.protobuf.nano.testimport";
//option java_outer_classname = "UnittestImportNano";
message ImportMessageNano {