From ffedb624429709fa325572da1c5ecebc3bfc03d0 Mon Sep 17 00:00:00 2001 From: Reynold Xin Date: Wed, 10 Jun 2015 14:52:11 -0700 Subject: [PATCH] Code review feedback. Still need to fix test failure. --- .../java/org/apache/spark/unsafe/types/UTF8String.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java b/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java index cb9081b7dd9a7..8f3bcbd1c4d67 100644 --- a/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java +++ b/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java @@ -22,6 +22,8 @@ import java.util.Arrays; import javax.annotation.Nullable; +import org.apache.spark.unsafe.PlatformDependent; + /** * A UTF-8 String for internal Spark use. *

@@ -35,7 +37,7 @@ public final class UTF8String implements Comparable, Serializable { @Nullable private byte[] bytes; - private int[] bytesOfCodePointInUTF8 = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + private static int[] bytesOfCodePointInUTF8 = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, @@ -156,8 +158,10 @@ public String toString() { try { return new String(bytes, "utf-8"); } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - return "unsupported encoding"; + // Turn the exception into unchecked so we can find out about it at runtime, but + // don't need to add lots of boilerplate code everywhere. + PlatformDependent.throwException(e); + return "unknown"; // we will never reach here. } }