HADOOP-16453. Update how exceptions are handled in NetUtils. Contributed by Lisheng Sun.

This commit is contained in:
Inigo Goiri 2019-08-11 20:34:36 -07:00
parent cf5d8957ee
commit 6b4564f1d5
3 changed files with 15 additions and 17 deletions

View File

@ -804,7 +804,11 @@ public static IOException wrapException(final String destHost,
+ ";"
+ see("SocketException"));
} else {
// Return instance of same type if Exception has a String constructor
// 1. Return instance of same type with exception msg if Exception has a
// String constructor.
// 2. Return instance of same type if Exception doesn't have a String
// constructor.
// Related HADOOP-16453.
return wrapWithMessage(exception,
"DestHost:destPort " + destHost + ":" + destPort
+ " , LocalHost:localPort " + localHost
@ -832,9 +836,9 @@ private static <T extends IOException> T wrapWithMessage(
Constructor<? extends Throwable> ctor = clazz.getConstructor(String.class);
Throwable t = ctor.newInstance(msg);
return (T)(t.initCause(exception));
} catch (NoSuchMethodException e) {
return exception;
} catch (Throwable e) {
LOG.trace("Unable to wrap exception of type {}: it has no (String) "
+ "constructor", clazz, e);
throw exception;
}
}

View File

@ -1582,11 +1582,10 @@ public void testRpcResponseLimit() throws Throwable {
try {
call(client, 0, addr, conf);
} catch (IOException ioe) {
Throwable t = ioe.getCause();
Assert.assertNotNull(t);
Assert.assertEquals(RpcException.class, t.getClass());
Assert.assertNotNull(ioe);
Assert.assertEquals(RpcException.class, ioe.getClass());
Assert.assertEquals("RPC response exceeds maximum data length",
t.getMessage());
ioe.getMessage());
return;
}
Assert.fail("didn't get limit exceeded");

View File

@ -279,11 +279,9 @@ public void testWrapKerbAuthException() throws Throwable {
@Test
public void testWrapIOEWithNoStringConstructor() throws Throwable {
IOException e = new CharacterCodingException();
IOException wrapped = verifyExceptionClass(e, IOException.class);
assertInException(wrapped, "Failed on local exception");
assertNotInException(wrapped, NetUtils.HADOOP_WIKI);
assertInException(wrapped, "Host Details ");
assertRemoteDetailsIncluded(wrapped);
IOException wrapped =
verifyExceptionClass(e, CharacterCodingException.class);
assertEquals(null, wrapped.getMessage());
}
@Test
@ -295,11 +293,8 @@ private TestIOException(String cause){
}
}
IOException e = new TestIOException();
IOException wrapped = verifyExceptionClass(e, IOException.class);
assertInException(wrapped, "Failed on local exception");
assertNotInException(wrapped, NetUtils.HADOOP_WIKI);
assertInException(wrapped, "Host Details ");
assertRemoteDetailsIncluded(wrapped);
IOException wrapped = verifyExceptionClass(e, TestIOException.class);
assertEquals(null, wrapped.getMessage());
}
@Test