Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Unified Diff: third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java
index 43736dd10d4370a11f0ff87adf29030a46538173..046030f3d5282234679c20b736f877ec57ffd117 100644
--- a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java
@@ -45,10 +45,10 @@ import java.util.Collection;
*/
public abstract class AbstractMessageLite<
MessageType extends AbstractMessageLite<MessageType, BuilderType>,
- BuilderType extends AbstractMessageLite.Builder<MessageType, BuilderType>>
+ BuilderType extends AbstractMessageLite.Builder<MessageType, BuilderType>>
implements MessageLite {
protected int memoizedHashCode = 0;
-
+
@Override
public ByteString toByteString() {
try {
@@ -57,9 +57,7 @@ public abstract class AbstractMessageLite<
writeTo(out.getCodedOutput());
return out.build();
} catch (IOException e) {
- throw new RuntimeException(
- "Serializing to a ByteString threw an IOException (should " +
- "never happen).", e);
+ throw new RuntimeException(getSerializingExceptionMessage("ByteString"), e);
}
}
@@ -72,9 +70,7 @@ public abstract class AbstractMessageLite<
output.checkNoSpaceLeft();
return result;
} catch (IOException e) {
- throw new RuntimeException(
- "Serializing to a byte array threw an IOException " +
- "(should never happen).", e);
+ throw new RuntimeException(getSerializingExceptionMessage("byte array"), e);
}
}
@@ -109,6 +105,11 @@ public abstract class AbstractMessageLite<
return new UninitializedMessageException(this);
}
+ private String getSerializingExceptionMessage(String target) {
+ return "Serializing " + getClass().getName() + " to a " + target
+ + " threw an IOException (should never happen).";
+ }
+
protected static void checkByteStringIsUtf8(ByteString byteString)
throws IllegalArgumentException {
if (!byteString.isValidUtf8()) {
@@ -120,7 +121,7 @@ public abstract class AbstractMessageLite<
final Collection<? super T> list) {
Builder.addAll(values, list);
}
-
+
/**
* A partial implementation of the {@link Message.Builder} interface which
* implements as many methods of that interface as possible in terms of
@@ -156,9 +157,7 @@ public abstract class AbstractMessageLite<
} catch (InvalidProtocolBufferException e) {
throw e;
} catch (IOException e) {
- throw new RuntimeException(
- "Reading from a ByteString threw an IOException (should " +
- "never happen).", e);
+ throw new RuntimeException(getReadingExceptionMessage("ByteString"), e);
}
}
@@ -174,9 +173,7 @@ public abstract class AbstractMessageLite<
} catch (InvalidProtocolBufferException e) {
throw e;
} catch (IOException e) {
- throw new RuntimeException(
- "Reading from a ByteString threw an IOException (should " +
- "never happen).", e);
+ throw new RuntimeException(getReadingExceptionMessage("ByteString"), e);
}
}
@@ -197,9 +194,7 @@ public abstract class AbstractMessageLite<
} catch (InvalidProtocolBufferException e) {
throw e;
} catch (IOException e) {
- throw new RuntimeException(
- "Reading from a byte array threw an IOException (should " +
- "never happen).", e);
+ throw new RuntimeException(getReadingExceptionMessage("byte array"), e);
}
}
@@ -225,9 +220,7 @@ public abstract class AbstractMessageLite<
} catch (InvalidProtocolBufferException e) {
throw e;
} catch (IOException e) {
- throw new RuntimeException(
- "Reading from a byte array threw an IOException (should " +
- "never happen).", e);
+ throw new RuntimeException(getReadingExceptionMessage("byte array"), e);
}
}
@@ -321,7 +314,7 @@ public abstract class AbstractMessageLite<
return mergeDelimitedFrom(input,
ExtensionRegistryLite.getEmptyRegistry());
}
-
+
@Override
@SuppressWarnings("unchecked") // isInstance takes care of this
public BuilderType mergeFrom(final MessageLite other) {
@@ -329,12 +322,17 @@ public abstract class AbstractMessageLite<
throw new IllegalArgumentException(
"mergeFrom(MessageLite) can only merge messages of the same type.");
}
-
+
return internalMergeFrom((MessageType) other);
}
-
+
protected abstract BuilderType internalMergeFrom(MessageType message);
+ private String getReadingExceptionMessage(String target) {
+ return "Reading " + getClass().getName() + " from a " + target
+ + " threw an IOException (should never happen).";
+ }
+
/**
* Construct an UninitializedMessageException reporting missing fields in
* the given message.

Powered by Google App Engine
This is Rietveld 408576698