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 --- .../protobuf/nano/ExtendableMessageNano.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'java/src/main/java') 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()); + } } -- cgit v1.1