From 11f883e185a2ea6fd6d0b19520e9f0f004e90e5c Mon Sep 17 00:00:00 2001 From: Max Cai Date: Tue, 15 Jul 2014 15:15:28 +0100 Subject: Fix access around unknownFieldData. Instead of publishing its class I chose to encapsulate the troublesome references in equals()/hashCode() in the generated code into superclass methods in ExtendableMessageNano. Changed a couple of java packages in the test suite to catch this issue easier in the future. Change-Id: I43f88411f63bb6f3ffc8d63361f2f77bebf6220a --- .../com/google/protobuf/nano/NanoAndroidTest.java | 4 ++-- .../protobuf/nano/ExtendableMessageNano.java | 25 ++++++++++++++++++++++ .../test/java/com/google/protobuf/NanoTest.java | 8 +++---- 3 files changed, 31 insertions(+), 6 deletions(-) (limited to 'java/src') 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> 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; -- cgit v1.1