Skip to content

Commit

Permalink
Use an explicit locale when formatting OutOfSpaceException.
Browse files Browse the repository at this point in the history
Implicitly using the default locale is a common source of bugs:
https://developer.android.com/reference/java/util/Locale.html#default_locale

PiperOrigin-RevId: 679381814
  • Loading branch information
mhansen authored and copybara-github committed Sep 27, 2024
1 parent 01f94be commit 0ea9685
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -962,7 +963,7 @@ public static class OutOfSpaceException extends IOException {
}

OutOfSpaceException(long position, long limit, int length, Throwable cause) {
this(String.format("Pos: %d, limit: %d, len: %d", position, limit, length), cause);
this(String.format(Locale.US, "Pos: %d, limit: %d, len: %d", position, limit, length), cause);
}
}

Expand Down Expand Up @@ -1168,8 +1169,11 @@ private static class ArrayEncoder extends CodedOutputStream {
if ((offset | length | (buffer.length - (offset + length))) < 0) {
throw new IllegalArgumentException(
String.format(
Locale.US,
"Array range is invalid. Buffer.length=%d, offset=%d, length=%d",
buffer.length, offset, length));
buffer.length,
offset,
length));
}
this.buffer = buffer;
this.offset = offset;
Expand Down

0 comments on commit 0ea9685

Please sign in to comment.