Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static com.google.protobuf.Internal.checkNotNull;

import java.nio.ByteBuffer;
import java.util.Locale;

/**
* A buffer that was allocated by a {@link BufferAllocator}. For every buffer, it is guaranteed that
Expand Down Expand Up @@ -119,7 +120,8 @@ public static AllocatedBuffer wrap(byte[] bytes) {
public static AllocatedBuffer wrap(final byte[] bytes, final int offset, final int length) {
if (offset < 0 || length < 0 || (offset + length) > bytes.length) {
throw new IndexOutOfBoundsException(
String.format("bytes.length=%d, offset=%d, length=%d", bytes.length, offset, length));
String.format(
Locale.ROOT, "bytes.length=%d, offset=%d, length=%d", bytes.length, offset, length));
}

return wrapNoCheck(bytes, offset, length);
Expand Down
15 changes: 13 additions & 2 deletions java/core/src/main/java/com/google/protobuf/BinaryWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.nio.ByteOrder;
import java.util.ArrayDeque;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Queue;

Expand Down Expand Up @@ -1905,7 +1906,12 @@ public void write(byte value) {
public void write(byte[] value, int offset, int length) {
if (offset < 0 || offset + length > value.length) {
throw new ArrayIndexOutOfBoundsException(
String.format("value.length=%d, offset=%d, length=%d", value.length, offset, length));
String.format(
Locale.ROOT,
"value.length=%d, offset=%d, length=%d",
value.length,
offset,
length));
}
requireSpace(length);

Expand All @@ -1917,7 +1923,12 @@ public void write(byte[] value, int offset, int length) {
public void writeLazy(byte[] value, int offset, int length) {
if (offset < 0 || offset + length > value.length) {
throw new ArrayIndexOutOfBoundsException(
String.format("value.length=%d, offset=%d, length=%d", value.length, offset, length));
String.format(
Locale.ROOT,
"value.length=%d, offset=%d, length=%d",
value.length,
offset,
length));
}
if (spaceLeft() < length) {
// We consider the value to be immutable (likely the internals of a ByteString). Just
Expand Down
4 changes: 3 additions & 1 deletion java/core/src/main/java/com/google/protobuf/FieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;

Expand Down Expand Up @@ -1311,8 +1312,9 @@ private void verifyType(final T descriptor, final Object value) {
}
throw new IllegalArgumentException(
String.format(
Locale.ROOT,
"Wrong object type used with protocol message reflection.\n"
+ "Field number: %d, field java type: %s, value type: %s\n",
+ "Field number: %d, field java type: %s, value type: %s\n",
descriptor.getNumber(),
descriptor.getLiteType().getJavaType(),
value.getClass().getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static void validateProtobufGencodeVersionImpl(
if (domain != DOMAIN) {
throw new ProtobufRuntimeVersionException(
String.format(
Locale.US,
Locale.ROOT,
"Detected mismatched Protobuf Gencode/Runtime domains when loading %s: gencode %s,"
+ " runtime %s. Cross-domain usage of Protobuf is not supported.",
location,
Expand All @@ -104,7 +104,7 @@ private static void validateProtobufGencodeVersionImpl(
}
logger.warning(
String.format(
Locale.US,
Locale.ROOT,
" Protobuf prelease version %s in use. This is not recommended for "
+ "production use.\n"
+ " You can ignore this message if you are deliberately testing a prerelease."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;

Expand Down Expand Up @@ -128,8 +129,10 @@ private static <T> T getFromList(List<T> list, int index, FieldDescriptor fieldD
if (index >= list.size() || index < 0) {
throw new IllegalArgumentException(
String.format(
Locale.ROOT,
"Illegal index field: %s, index %d",
fieldDescriptor == null ? "<null>" : fieldDescriptor.getName(), index));
fieldDescriptor == null ? "<null>" : fieldDescriptor.getName(),
index));
}
return list.get(index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.google.protobuf;

import java.util.Arrays;
import java.util.Locale;

/**
* A location in the source code.
Expand All @@ -32,7 +33,11 @@ static TextFormatParseLocation create(int line, int column) {
}
if (line < 0 || column < 0) {
throw new IllegalArgumentException(
String.format("line and column values must be >= 0: line %d, column: %d", line, column));
String.format(
Locale.ROOT,
"line and column values must be >= 0: line %d, column: %d",
line,
column));
}
return new TextFormatParseLocation(line, column);
}
Expand All @@ -55,7 +60,7 @@ public int getColumn() {

@Override
public String toString() {
return String.format("ParseLocation{line=%d, column=%d}", line, column);
return String.format(Locale.ROOT, "ParseLocation{line=%d, column=%d}", line, column);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Random;

/**
Expand Down Expand Up @@ -291,7 +292,7 @@ private static String toHexString(byte[] b, int len) {
if (i > 0) {
s.append(" ");
}
s.append(String.format("%02x", b[i] & 0xFF));
s.append(String.format(Locale.ROOT, "%02x", b[i] & 0xFF));
}
s.append("\"");
return s.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TreeMap;
Expand Down Expand Up @@ -245,6 +246,7 @@ private static void merge(
if (source.getDescriptorForType() != destination.getDescriptorForType()) {
throw new IllegalArgumentException(
String.format(
Locale.ROOT,
"source (%s) and destination (%s) descriptor must be equal",
source.getDescriptorForType().getFullName(),
destination.getDescriptorForType().getFullName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,9 @@ public void testTimestampMergeError() throws Exception {
final String incorrectTimestampString = "{\"seconds\":1800,\"nanos\":0}";
try {
TestTimestamp.Builder builder = TestTimestamp.newBuilder();
mergeFromJson(String.format("{\"timestamp_value\": %s}", incorrectTimestampString), builder);
mergeFromJson(
String.format(Locale.ROOT, "{\"timestamp_value\": %s}", incorrectTimestampString),
builder);
assertWithMessage("expected exception").fail();
} catch (InvalidProtocolBufferException e) {
// Exception expected.
Expand All @@ -924,7 +926,8 @@ public void testDurationMergeError() throws Exception {
final String incorrectDurationString = "{\"seconds\":10,\"nanos\":500}";
try {
TestDuration.Builder builder = TestDuration.newBuilder();
mergeFromJson(String.format("{\"duration_value\": %s}", incorrectDurationString), builder);
mergeFromJson(
String.format(Locale.ROOT, "{\"duration_value\": %s}", incorrectDurationString), builder);
assertWithMessage("expected exception").fail();
} catch (InvalidProtocolBufferException e) {
// Exception expected.
Expand Down
Loading