MAPREDUCE-1621. Fixes NPE in TextOutputReader.getLastOutput if it has never read any output. Contributed by Amareshwari Sriramadasu
git-svn-id: https://svn.apache.org/repos/asf/hadoop/mapreduce/trunk@964752 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES.txt b/CHANGES.txt
index 230fb83..0769aa2 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -170,6 +170,9 @@
MAPREDUCE-1865. Rumen should also support jobhistory files generated using
trunk. (Amar Kamat via amareshwari)
+ MAPREDUCE-1621. Fixes NPE in TextOutputReader.getLastOutput if it has never
+ read any output. (amareshwari)
+
Release 0.21.0 - Unreleased
INCOMPATIBLE CHANGES
diff --git a/src/contrib/streaming/src/java/org/apache/hadoop/streaming/io/RawBytesOutputReader.java b/src/contrib/streaming/src/java/org/apache/hadoop/streaming/io/RawBytesOutputReader.java
index 3242fc9..2ffb62c 100644
--- a/src/contrib/streaming/src/java/org/apache/hadoop/streaming/io/RawBytesOutputReader.java
+++ b/src/contrib/streaming/src/java/org/apache/hadoop/streaming/io/RawBytesOutputReader.java
@@ -68,7 +68,11 @@
@Override
public String getLastOutput() {
- return new BytesWritable(bytes).toString();
+ if (bytes != null) {
+ return new BytesWritable(bytes).toString();
+ } else {
+ return null;
+ }
}
private int readLength() throws IOException {
diff --git a/src/contrib/streaming/src/java/org/apache/hadoop/streaming/io/TextOutputReader.java b/src/contrib/streaming/src/java/org/apache/hadoop/streaming/io/TextOutputReader.java
index b8d7ca2..06c05bc 100644
--- a/src/contrib/streaming/src/java/org/apache/hadoop/streaming/io/TextOutputReader.java
+++ b/src/contrib/streaming/src/java/org/apache/hadoop/streaming/io/TextOutputReader.java
@@ -83,10 +83,14 @@
@Override
public String getLastOutput() {
- try {
- return new String(bytes, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- return "<undecodable>";
+ if (bytes != null) {
+ try {
+ return new String(bytes, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ return "<undecodable>";
+ }
+ } else {
+ return null;
}
}
diff --git a/src/contrib/streaming/src/java/org/apache/hadoop/streaming/io/TypedBytesOutputReader.java b/src/contrib/streaming/src/java/org/apache/hadoop/streaming/io/TypedBytesOutputReader.java
index a032579..e5526ef 100644
--- a/src/contrib/streaming/src/java/org/apache/hadoop/streaming/io/TypedBytesOutputReader.java
+++ b/src/contrib/streaming/src/java/org/apache/hadoop/streaming/io/TypedBytesOutputReader.java
@@ -70,7 +70,11 @@
@Override
public String getLastOutput() {
- return new TypedBytesWritable(bytes).toString();
+ if (bytes != null) {
+ return new TypedBytesWritable(bytes).toString();
+ } else {
+ return null;
+ }
}
}