hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From deva...@apache.org
Subject hadoop git commit: YARN-3745. SerializedException should also try to instantiate internal exception with the default constructor. Contributed by Lavkesh Lahngir.
Date Thu, 25 Jun 2015 12:11:07 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 3e20f595d -> bb8a2cff2


YARN-3745. SerializedException should also try to instantiate internal
exception with the default constructor. Contributed by Lavkesh Lahngir.

(cherry picked from commit b381f88c71d18497deb35039372b1e9715d2c038)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/bb8a2cff
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/bb8a2cff
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/bb8a2cff

Branch: refs/heads/branch-2
Commit: bb8a2cff2af4b09fedd6b27114ae99ace84e5aa8
Parents: 3e20f59
Author: Devaraj K <devaraj@apache.org>
Authored: Thu Jun 25 17:38:11 2015 +0530
Committer: Devaraj K <devaraj@apache.org>
Committed: Thu Jun 25 17:39:40 2015 +0530

----------------------------------------------------------------------
 hadoop-yarn-project/CHANGES.txt                 |  3 +++
 .../impl/pb/SerializedExceptionPBImpl.java      | 26 ++++++++++++++++----
 .../impl/pb/TestSerializedExceptionPBImpl.java  | 11 +++++++++
 3 files changed, 35 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/bb8a2cff/hadoop-yarn-project/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt
index d4f23b6..2290b21 100644
--- a/hadoop-yarn-project/CHANGES.txt
+++ b/hadoop-yarn-project/CHANGES.txt
@@ -508,6 +508,9 @@ Release 2.8.0 - UNRELEASED
     YARN-3826. Race condition in ResourceTrackerService leads to
     wrong diagnostics messages. (Chengbing Liu via devaraj)
 
+    YARN-3745. SerializedException should also try to instantiate internal
+    exception with the default constructor. (Lavkesh Lahngir via devaraj)
+
 Release 2.7.1 - UNRELEASED
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/hadoop/blob/bb8a2cff/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/SerializedExceptionPBImpl.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/SerializedExceptionPBImpl.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/SerializedExceptionPBImpl.java
index e683fd5..fd9e170 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/SerializedExceptionPBImpl.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/SerializedExceptionPBImpl.java
@@ -158,15 +158,31 @@ public class SerializedExceptionPBImpl extends SerializedException {
     viaProto = false;
   }
 
+  private static <T extends Throwable> T instantiateExceptionImpl(
+      String message, Class<? extends T> cls, Throwable cause)
+      throws NoSuchMethodException, InstantiationException,
+      IllegalAccessException, InvocationTargetException {
+    Constructor<? extends T> cn;
+    T ex = null;
+    cn =
+        cls.getConstructor(message == null ? new Class[0]
+            : new Class[] {String.class});
+    cn.setAccessible(true);
+    ex = message == null ? cn.newInstance() : cn.newInstance(message);
+    ex.initCause(cause);
+    return ex;
+  }
+
   private static <T extends Throwable> T instantiateException(
       Class<? extends T> cls, String message, Throwable cause) {
-    Constructor<? extends T> cn;
     T ex = null;
     try {
-      cn = cls.getConstructor(String.class);
-      cn.setAccessible(true);
-      ex = cn.newInstance(message);
-      ex.initCause(cause);
+      // Try constructor with String argument, if it fails, try default.
+      try {
+        ex = instantiateExceptionImpl(message, cls, cause);
+      } catch (NoSuchMethodException e) {
+        ex = instantiateExceptionImpl(null, cls, cause);
+      }
     } catch (SecurityException e) {
       throw new YarnRuntimeException(e);
     } catch (NoSuchMethodException e) {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/bb8a2cff/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/records/impl/pb/TestSerializedExceptionPBImpl.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/records/impl/pb/TestSerializedExceptionPBImpl.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/records/impl/pb/TestSerializedExceptionPBImpl.java
index b011e3e..ac7e40e 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/records/impl/pb/TestSerializedExceptionPBImpl.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/records/impl/pb/TestSerializedExceptionPBImpl.java
@@ -18,6 +18,8 @@
 
 package org.apache.hadoop.yarn.api.records.impl.pb;
 
+import java.nio.channels.ClosedChannelException;
+
 import org.junit.Assert;
 import org.apache.hadoop.yarn.api.records.impl.pb.SerializedExceptionPBImpl;
 import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
@@ -55,6 +57,15 @@ public class TestSerializedExceptionPBImpl {
   }
 
   @Test
+  public void testDeserializeWithDefaultConstructor() {
+    // Init SerializedException with an Exception with default constructor.
+    ClosedChannelException ex = new ClosedChannelException();
+    SerializedExceptionPBImpl pb = new SerializedExceptionPBImpl();
+    pb.init(ex);
+    Assert.assertEquals(ex.getClass(), pb.deSerialize().getClass());
+  }
+
+  @Test
   public void testBeforeInit() throws Exception {
     SerializedExceptionProto defaultProto =
         SerializedExceptionProto.newBuilder().build();


Mime
View raw message