aboutsummaryrefslogtreecommitdiff
path: root/java/src/main/java/com/google/protobuf/AbstractMessageLite.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/main/java/com/google/protobuf/AbstractMessageLite.java')
-rw-r--r--java/src/main/java/com/google/protobuf/AbstractMessageLite.java24
1 files changed, 18 insertions, 6 deletions
diff --git a/java/src/main/java/com/google/protobuf/AbstractMessageLite.java b/java/src/main/java/com/google/protobuf/AbstractMessageLite.java
index 9926f3db..bce713b0 100644
--- a/java/src/main/java/com/google/protobuf/AbstractMessageLite.java
+++ b/java/src/main/java/com/google/protobuf/AbstractMessageLite.java
@@ -44,6 +44,8 @@ import java.util.Collection;
* @author kenton@google.com Kenton Varda
*/
public abstract class AbstractMessageLite implements MessageLite {
+ protected int memoizedHashCode = 0;
+
public ByteString toByteString() {
try {
final ByteString.CodedBuilder out =
@@ -91,6 +93,7 @@ public abstract class AbstractMessageLite implements MessageLite {
codedOutput.flush();
}
+
/**
* Package private helper method for AbstractParser to create
* UninitializedMessageException.
@@ -99,6 +102,13 @@ public abstract class AbstractMessageLite implements MessageLite {
return new UninitializedMessageException(this);
}
+ protected static void checkByteStringIsUtf8(ByteString byteString)
+ throws IllegalArgumentException {
+ if (!byteString.isValidUtf8()) {
+ throw new IllegalArgumentException("Byte string is not UTF-8.");
+ }
+ }
+
/**
* A partial implementation of the {@link Message.Builder} interface which
* implements as many methods of that interface as possible in terms of
@@ -311,7 +321,8 @@ public abstract class AbstractMessageLite implements MessageLite {
* used by generated code. Users should ignore it.
*
* @throws NullPointerException if any of the elements of {@code values} is
- * null.
+ * null. When that happens, some elements of {@code values} may have already
+ * been added to the result {@code list}.
*/
protected static <T> void addAll(final Iterable<T> values,
final Collection<? super T> list) {
@@ -319,14 +330,15 @@ public abstract class AbstractMessageLite implements MessageLite {
// For StringOrByteStringLists, check the underlying elements to avoid
// forcing conversions of ByteStrings to Strings.
checkForNullValues(((LazyStringList) values).getUnderlyingElements());
- } else {
+ list.addAll((Collection<T>) values);
+ } else if (values instanceof Collection) {
checkForNullValues(values);
- }
- if (values instanceof Collection) {
- final Collection<T> collection = (Collection<T>) values;
- list.addAll(collection);
+ list.addAll((Collection<T>) values);
} else {
for (final T value : values) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
list.add(value);
}
}