diff --git a/LICENSE-binary b/LICENSE-binary index db4e5fba98b10..f5e778ae143e0 100644 --- a/LICENSE-binary +++ b/LICENSE-binary @@ -218,12 +218,12 @@ com.aliyun:aliyun-java-sdk-sts:3.0.0 com.aliyun.oss:aliyun-sdk-oss:3.13.2 com.cedarsoftware:java-util:1.9.0 com.cedarsoftware:json-io:2.5.1 -com.fasterxml.jackson.core:jackson-annotations:2.12.7 -com.fasterxml.jackson.core:jackson-core:2.12.7 -com.fasterxml.jackson.core:jackson-databind:2.12.7.1 -com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:2.12.7 -com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.12.7 -com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.12.7 +com.fasterxml.jackson.core:jackson-annotations:2.14.3 +com.fasterxml.jackson.core:jackson-core:2.14.3 +com.fasterxml.jackson.core:jackson-databind:2.14.3 +com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:2.14.3 +com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.14.3 +com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.14.3 com.fasterxml.uuid:java-uuid-generator:3.1.4 com.fasterxml.woodstox:woodstox-core:5.4.0 com.github.ben-manes.caffeine:caffeine:2.9.3 @@ -505,8 +505,7 @@ javax.cache:cache-api:1.1.1 javax.servlet:javax.servlet-api:3.1.0 javax.servlet.jsp:jsp-api:2.1 javax.websocket:javax.websocket-api:1.0 -javax.ws.rs:jsr311-api:1.1.1 -javax.xml.bind:jaxb-api:2.2.11 +javax.xml.bind:jaxb-api:2.3.1 Eclipse Distribution License (EDL) 1.0 -------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java index 3a4f4fd37d3f8..58a5ffa79103d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.lang.reflect.Constructor; import java.net.BindException; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -46,10 +45,6 @@ import javax.net.SocketFactory; -import org.apache.hadoop.security.AccessControlException; -import org.apache.hadoop.thirdparty.com.google.common.cache.Cache; -import org.apache.hadoop.thirdparty.com.google.common.cache.CacheBuilder; - import org.apache.commons.net.util.SubnetUtils; import org.apache.commons.net.util.SubnetUtils.SubnetInfo; import org.apache.hadoop.classification.InterfaceAudience; @@ -58,9 +53,13 @@ import org.apache.hadoop.fs.CommonConfigurationKeysPublic; import org.apache.hadoop.ipc.Server; import org.apache.hadoop.ipc.VersionedProtocol; +import org.apache.hadoop.security.AccessControlException; import org.apache.hadoop.security.SecurityUtil; +import org.apache.hadoop.thirdparty.com.google.common.cache.Cache; +import org.apache.hadoop.thirdparty.com.google.common.cache.CacheBuilder; import org.apache.hadoop.util.ReflectionUtils; import org.apache.hadoop.util.Preconditions; +import org.apache.hadoop.util.dynamic.DynConstructors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -941,10 +940,59 @@ public static IOException wrapException(final String destHost, } } catch (IOException ex) { - return (IOException) new IOException("Failed on local exception: " - + exception + "; Host Details : " - + getHostDetailsAsString(destHost, destPort, localHost)) - .initCause(exception); + try { + return new IOException("Failed on local exception: " + + exception + "; Host Details : " + + getHostDetailsAsString(destHost, destPort, localHost), exception); + } catch (Exception ignore) { + // in worst case, return the original exception + return exception; + } + } + } + + /** + * Return an @{@link IOException} of the same type as the input exception but with + * a modified exception message that includes the node name. + * + * @param ioe existing exception. + * @param nodeName name of the node. + * @return IOException + */ + public static IOException addNodeNameToIOException(final IOException ioe, final String nodeName) { + try { + final Throwable cause = ioe.getCause(); + IOException newIoe = null; + if (cause != null) { + try { + DynConstructors.Ctor ctor = + new DynConstructors.Builder() + .impl(ioe.getClass(), String.class, Throwable.class) + .buildChecked(); + newIoe = ctor.newInstance(nodeName + ": " + ioe.getMessage(), cause); + } catch (NoSuchMethodException e) { + // no matching constructor - try next approach below + } + } + if (newIoe == null) { + DynConstructors.Ctor ctor = + new DynConstructors.Builder() + .impl(ioe.getClass(), String.class) + .buildChecked(); + newIoe = ctor.newInstance(nodeName + ": " + ioe.getMessage()); + if (cause != null) { + try { + newIoe.initCause(cause); + } catch (Exception e) { + // Unable to initCause. Ignore the exception. + } + } + } + newIoe.setStackTrace(ioe.getStackTrace()); + return newIoe; + } catch (Exception e) { + // Unable to create new exception. Return the original exception. + return ioe; } } @@ -957,9 +1005,22 @@ private static T wrapWithMessage( T exception, String msg) throws T { Class clazz = exception.getClass(); try { - Constructor ctor = clazz.getConstructor(String.class); - Throwable t = ctor.newInstance(msg); - return (T)(t.initCause(exception)); + try { + DynConstructors.Ctor ctor = + new DynConstructors.Builder() + .impl(clazz, String.class, Throwable.class) + .buildChecked(); + return ctor.newInstance(msg, exception); + } catch (NoSuchMethodException e) { + // no matching constructor - try next approach below + } + DynConstructors.Ctor ctor = + new DynConstructors.Builder() + .impl(clazz, String.class) + .buildChecked(); + T newException = ctor.newInstance(msg); + newException.initCause(exception); + return newException; } catch (NoSuchMethodException e) { return exception; } catch (Throwable e) { @@ -1114,7 +1175,7 @@ public static Set getFreeSocketPorts(int numOfPorts) { /** * Return an @{@link InetAddress} to bind to. If bindWildCardAddress is true - * than returns null. + * then returns null. * * @param localAddr local addr. * @param bindWildCardAddress bind wildcard address. diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestNetUtils.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestNetUtils.java index 0b2d0b8abc821..7a2dc0cc194c3 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestNetUtils.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestNetUtils.java @@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -44,6 +45,7 @@ import java.util.Enumeration; import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.zip.ZipException; import org.apache.commons.lang3.StringUtils; import org.apache.hadoop.conf.Configuration; @@ -801,9 +803,57 @@ public void testBindToLocalAddress() throws Exception { .bindToLocalAddress(NetUtils.getLocalInetAddress("127.0.0.1"), true)); } + public static class WrappedIOException extends IOException { + public WrappedIOException(String msg, Throwable cause) { + super(msg, cause); + } + } + + private static class PrivateIOException extends IOException { + PrivateIOException(String msg, Throwable cause) { + super(msg, cause); + } + } + + @Test + public void testAddNodeNameToIOException() { + IOException e0 = new IOException("test123"); + assertNullCause(e0); + IOException new0 = NetUtils.addNodeNameToIOException(e0, "node123"); + assertNullCause(new0); + assertEquals("node123: test123", new0.getMessage()); + + IOException e1 = new IOException("test456", new IllegalStateException("deliberate")); + IOException new1 = NetUtils.addNodeNameToIOException(e1, "node456"); + assertSame(e1.getCause(), new1.getCause()); + assertEquals("node456: test456", new1.getMessage()); + + ZipException e2 = new ZipException("test789"); + assertNullCause(e2); + IOException new2 = NetUtils.addNodeNameToIOException(e2, "node789"); + assertNullCause(new2); + assertEquals("node789: test789", new2.getMessage()); + + WrappedIOException e3 = new WrappedIOException("test987", + new IllegalStateException("deliberate")); + IOException new3 = NetUtils.addNodeNameToIOException(e3, "node987"); + assertSame(e3.getCause(), new3.getCause()); + assertEquals("node987: test987", new3.getMessage()); + + // addNodeNameToIOException will return the original exception if the class is not accessible + PrivateIOException e4 = new PrivateIOException("test654", + new IllegalStateException("deliberate")); + IOException new4 = NetUtils.addNodeNameToIOException(e4, "node654"); + assertSame(e4, new4); + } + private void assertBetterArrayEquals(T[] expect, T[]got) { String expectStr = StringUtils.join(expect, ", "); String gotStr = StringUtils.join(got, ", "); assertEquals(expectStr, gotStr); } + + private void assertNullCause(Exception e) { + assertNull(e.getCause(), "Expected exception to have null cause"); + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java index d0607e96dc42b..29d7fbed8963e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java @@ -31,7 +31,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.net.MalformedURLException; @@ -845,16 +844,7 @@ private T runWithRetry() throws IOException { if (node == null) { node = url.getAuthority(); } - try { - IOException newIoe = ioe.getClass().getConstructor(String.class) - .newInstance(node + ": " + ioe.getMessage()); - newIoe.initCause(ioe.getCause()); - newIoe.setStackTrace(ioe.getStackTrace()); - ioe = newIoe; - } catch (NoSuchMethodException | SecurityException - | InstantiationException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) { - } + ioe = NetUtils.addNodeNameToIOException(ioe, node); shouldRetry(ioe, retry); } } diff --git a/hadoop-project/pom.xml b/hadoop-project/pom.xml index 065085488fd1d..b80646d0d30e1 100644 --- a/hadoop-project/pom.xml +++ b/hadoop-project/pom.xml @@ -69,8 +69,8 @@ 2.46 - 2.12.7 - 2.12.7.1 + 2.14.3 + 2.14.3 4.5.13