Skip to content

Commit 42c27d1

Browse files
Use Locale.ROOT for all of our formatted error messages.
PiperOrigin-RevId: 845843886
1 parent 9cca3c1 commit 42c27d1

File tree

9 files changed

+38
-12
lines changed

9 files changed

+38
-12
lines changed

java/core/src/main/java/com/google/protobuf/AllocatedBuffer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ public static AllocatedBuffer wrap(byte[] bytes) {
119119
public static AllocatedBuffer wrap(final byte[] bytes, final int offset, final int length) {
120120
if (offset < 0 || length < 0 || (offset + length) > bytes.length) {
121121
throw new IndexOutOfBoundsException(
122-
String.format("bytes.length=%d, offset=%d, length=%d", bytes.length, offset, length));
122+
String.format(
123+
Locale.ROOT, "bytes.length=%d, offset=%d, length=%d", bytes.length, offset, length));
123124
}
124125

125126
return wrapNoCheck(bytes, offset, length);

java/core/src/main/java/com/google/protobuf/BinaryWriter.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.nio.ByteOrder;
2828
import java.util.ArrayDeque;
2929
import java.util.List;
30+
import java.util.Locale;
3031
import java.util.Map;
3132
import java.util.Queue;
3233

@@ -1905,7 +1906,12 @@ public void write(byte value) {
19051906
public void write(byte[] value, int offset, int length) {
19061907
if (offset < 0 || offset + length > value.length) {
19071908
throw new ArrayIndexOutOfBoundsException(
1908-
String.format("value.length=%d, offset=%d, length=%d", value.length, offset, length));
1909+
String.format(
1910+
Locale.ROOT,
1911+
"value.length=%d, offset=%d, length=%d",
1912+
value.length,
1913+
offset,
1914+
length));
19091915
}
19101916
requireSpace(length);
19111917

@@ -1917,7 +1923,12 @@ public void write(byte[] value, int offset, int length) {
19171923
public void writeLazy(byte[] value, int offset, int length) {
19181924
if (offset < 0 || offset + length > value.length) {
19191925
throw new ArrayIndexOutOfBoundsException(
1920-
String.format("value.length=%d, offset=%d, length=%d", value.length, offset, length));
1926+
String.format(
1927+
Locale.ROOT,
1928+
"value.length=%d, offset=%d, length=%d",
1929+
value.length,
1930+
offset,
1931+
length));
19211932
}
19221933
if (spaceLeft() < length) {
19231934
// We consider the value to be immutable (likely the internals of a ByteString). Just

java/core/src/main/java/com/google/protobuf/FieldSet.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Collections;
1616
import java.util.Iterator;
1717
import java.util.List;
18+
import java.util.Locale;
1819
import java.util.Map;
1920
import java.util.Map.Entry;
2021

@@ -1311,8 +1312,9 @@ private void verifyType(final T descriptor, final Object value) {
13111312
}
13121313
throw new IllegalArgumentException(
13131314
String.format(
1315+
Locale.ROOT,
13141316
"Wrong object type used with protocol message reflection.\n"
1315-
+ "Field number: %d, field java type: %s, value type: %s\n",
1317+
+ "Field number: %d, field java type: %s, value type: %s\n",
13161318
descriptor.getNumber(),
13171319
descriptor.getLiteType().getJavaType(),
13181320
value.getClass().getName()));

java/core/src/main/java/com/google/protobuf/RuntimeVersion.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private static void validateProtobufGencodeVersionImpl(
8888
if (domain != DOMAIN) {
8989
throw new ProtobufRuntimeVersionException(
9090
String.format(
91-
Locale.US,
91+
Locale.ROOT,
9292
"Detected mismatched Protobuf Gencode/Runtime domains when loading %s: gencode %s,"
9393
+ " runtime %s. Cross-domain usage of Protobuf is not supported.",
9494
location,
@@ -104,7 +104,7 @@ private static void validateProtobufGencodeVersionImpl(
104104
}
105105
logger.warning(
106106
String.format(
107-
Locale.US,
107+
Locale.ROOT,
108108
" Protobuf prelease version %s in use. This is not recommended for "
109109
+ "production use.\n"
110110
+ " You can ignore this message if you are deliberately testing a prerelease."

java/core/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Collections;
1313
import java.util.HashMap;
1414
import java.util.List;
15+
import java.util.Locale;
1516
import java.util.Map;
1617
import java.util.Map.Entry;
1718

@@ -128,8 +129,10 @@ private static <T> T getFromList(List<T> list, int index, FieldDescriptor fieldD
128129
if (index >= list.size() || index < 0) {
129130
throw new IllegalArgumentException(
130131
String.format(
132+
Locale.ROOT,
131133
"Illegal index field: %s, index %d",
132-
fieldDescriptor == null ? "<null>" : fieldDescriptor.getName(), index));
134+
fieldDescriptor == null ? "<null>" : fieldDescriptor.getName(),
135+
index));
133136
}
134137
return list.get(index);
135138
}

java/core/src/main/java/com/google/protobuf/TextFormatParseLocation.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package com.google.protobuf;
99

1010
import java.util.Arrays;
11+
import java.util.Locale;
1112

1213
/**
1314
* A location in the source code.
@@ -32,7 +33,11 @@ static TextFormatParseLocation create(int line, int column) {
3233
}
3334
if (line < 0 || column < 0) {
3435
throw new IllegalArgumentException(
35-
String.format("line and column values must be >= 0: line %d, column: %d", line, column));
36+
String.format(
37+
Locale.ROOT,
38+
"line and column values must be >= 0: line %d, column: %d",
39+
line,
40+
column));
3641
}
3742
return new TextFormatParseLocation(line, column);
3843
}
@@ -55,7 +60,7 @@ public int getColumn() {
5560

5661
@Override
5762
public String toString() {
58-
return String.format("ParseLocation{line=%d, column=%d}", line, column);
63+
return String.format(Locale.ROOT, "ParseLocation{line=%d, column=%d}", line, column);
5964
}
6065

6166
@Override

java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ private static String toHexString(byte[] b, int len) {
291291
if (i > 0) {
292292
s.append(" ");
293293
}
294-
s.append(String.format("%02x", b[i] & 0xFF));
294+
s.append(String.format(Locale.ROOT, "%02x", b[i] & 0xFF));
295295
}
296296
s.append("\"");
297297
return s.toString();

java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ private static void merge(
245245
if (source.getDescriptorForType() != destination.getDescriptorForType()) {
246246
throw new IllegalArgumentException(
247247
String.format(
248+
Locale.ROOT,
248249
"source (%s) and destination (%s) descriptor must be equal",
249250
source.getDescriptorForType().getFullName(),
250251
destination.getDescriptorForType().getFullName()));

java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,9 @@ public void testTimestampMergeError() throws Exception {
899899
final String incorrectTimestampString = "{\"seconds\":1800,\"nanos\":0}";
900900
try {
901901
TestTimestamp.Builder builder = TestTimestamp.newBuilder();
902-
mergeFromJson(String.format("{\"timestamp_value\": %s}", incorrectTimestampString), builder);
902+
mergeFromJson(
903+
String.format(Locale.ROOT, "{\"timestamp_value\": %s}", incorrectTimestampString),
904+
builder);
903905
assertWithMessage("expected exception").fail();
904906
} catch (InvalidProtocolBufferException e) {
905907
// Exception expected.
@@ -924,7 +926,8 @@ public void testDurationMergeError() throws Exception {
924926
final String incorrectDurationString = "{\"seconds\":10,\"nanos\":500}";
925927
try {
926928
TestDuration.Builder builder = TestDuration.newBuilder();
927-
mergeFromJson(String.format("{\"duration_value\": %s}", incorrectDurationString), builder);
929+
mergeFromJson(
930+
String.format(Locale.ROOT, "{\"duration_value\": %s}", incorrectDurationString), builder);
928931
assertWithMessage("expected exception").fail();
929932
} catch (InvalidProtocolBufferException e) {
930933
// Exception expected.

0 commit comments

Comments
 (0)