aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
diff options
context:
space:
mode:
authorBrian Duff <bduff@google.com>2015-04-21 23:08:37 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-04-21 23:08:37 +0000
commit63b42c8d7eb6b60fed296273513fc88b34b93469 (patch)
tree01ad6105786699579f9d3ceb7f2ba7ce3bb6b94b /java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
parent1d4b8b9fc9950152a1b235dfc83cf613a3b18ca4 (diff)
parent92f1bf25e822eb156a57b7ede390efb89e283a87 (diff)
downloadexternal_protobuf-63b42c8d7eb6b60fed296273513fc88b34b93469.zip
external_protobuf-63b42c8d7eb6b60fed296273513fc88b34b93469.tar.gz
external_protobuf-63b42c8d7eb6b60fed296273513fc88b34b93469.tar.bz2
am 92f1bf25: Merge "Throw OutOfSpaceException instead of IllegalArgumentException."
* commit '92f1bf25e822eb156a57b7ede390efb89e283a87': Throw OutOfSpaceException instead of IllegalArgumentException.
Diffstat (limited to 'java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java')
-rw-r--r--java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java11
1 files changed, 10 insertions, 1 deletions
diff --git a/java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java b/java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
index 324a63f..53060da 100644
--- a/java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
+++ b/java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
@@ -300,6 +300,12 @@ public final class CodedOutputByteBufferNano {
final int maxLengthVarIntSize = computeRawVarint32Size(value.length() * MAX_UTF8_EXPANSION);
if (minLengthVarIntSize == maxLengthVarIntSize) {
int oldPosition = buffer.position();
+ // Buffer.position, when passed a position that is past its limit, throws
+ // IllegalArgumentException, and this class is documented to throw
+ // OutOfSpaceException instead.
+ if (buffer.remaining() < minLengthVarIntSize) {
+ throw new OutOfSpaceException(oldPosition + minLengthVarIntSize, buffer.limit());
+ }
buffer.position(oldPosition + minLengthVarIntSize);
encode(value, buffer);
int newPosition = buffer.position();
@@ -311,7 +317,10 @@ public final class CodedOutputByteBufferNano {
encode(value, buffer);
}
} catch (BufferOverflowException e) {
- throw new OutOfSpaceException(buffer.position(), buffer.limit());
+ final OutOfSpaceException outOfSpaceException = new OutOfSpaceException(buffer.position(),
+ buffer.limit());
+ outOfSpaceException.initCause(e);
+ throw outOfSpaceException;
}
}