diff options
author | Jon Brandvein <brandjon@google.com> | 2017-01-03 14:40:20 +0000 |
---|---|---|
committer | John Cater <jcater@google.com> | 2017-01-03 15:06:28 +0000 |
commit | c9139896d49a12d69ca34fd47b3fa9d35c5a69a8 (patch) | |
tree | 0b2197de137377a218e0a12c2e4bef663137d105 /src/main/java/com/google/devtools/build/lib/events | |
parent | 2b6279a8a0afed3dcd1a4126aa141babaa7bd318 (diff) |
Change lib.events.Event to use UTF-8 encoding instead of a mix of platform-default and latin-1
--
PiperOrigin-RevId: 143439199
MOS_MIGRATED_REVID=143439199
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/events')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/events/Event.java | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/events/Event.java b/src/main/java/com/google/devtools/build/lib/events/Event.java index 0ba5cc8775..e5fb781b22 100644 --- a/src/main/java/com/google/devtools/build/lib/events/Event.java +++ b/src/main/java/com/google/devtools/build/lib/events/Event.java @@ -13,11 +13,10 @@ // limitations under the License. package com.google.devtools.build.lib.events; -import static java.nio.charset.StandardCharsets.ISO_8859_1; +import static java.nio.charset.StandardCharsets.UTF_8; import com.google.devtools.build.lib.util.Preconditions; import java.io.Serializable; -import java.nio.charset.Charset; import java.util.Arrays; import java.util.Objects; import javax.annotation.Nullable; @@ -37,10 +36,8 @@ public final class Event implements Serializable { * An alternative representation for message. * * <p>Exactly one of message or messageBytes will be non-null. If messageBytes is non-null, then - * it contains the bytes of the message (encoding currently unspecified). We do this to avoid - * converting back and forth between Strings and bytes. - * - * TODO(bazel-team): Fix the encoding to be consistent, e.g. use UTF-8 everywhere. + * it contains the UTF-8-encoded bytes of the message. We do this to avoid converting back and + * forth between Strings and bytes. */ private final byte[] messageBytes; @@ -77,12 +74,11 @@ public final class Event implements Serializable { } public String getMessage() { - // TODO(bazel-team): Don't rely on the platform default charset. - return message != null ? message : new String(messageBytes, Charset.defaultCharset()); + return message != null ? message : new String(messageBytes, UTF_8); } public byte[] getMessageBytes() { - return messageBytes != null ? messageBytes : message.getBytes(ISO_8859_1); + return messageBytes != null ? messageBytes : message.getBytes(UTF_8); } public EventKind getKind() { @@ -152,6 +148,8 @@ public final class Event implements Serializable { /** * Construct an event by passing in the {@code byte[]} array instead of a String. + * + * The bytes must be decodable as UTF-8 text. */ public static Event of(EventKind kind, @Nullable Location location, byte[] messageBytes) { return new Event(kind, location, messageBytes, null); |