steveloughran commented on code in PR #7428:
URL: https://github.com/apache/hadoop/pull/7428#discussion_r1967912307
##########
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java:
##########
@@ -846,14 +846,36 @@ private T runWithRetry() throws IOException {
node = url.getAuthority();
}
try {
- IOException newIoe = ioe.getClass().getConstructor(String.class)
- .newInstance(node + ": " + ioe.getMessage());
- newIoe.initCause(ioe.getCause());
+ final Throwable cause = ioe.getCause();
+ IOException newIoe = null;
+ if (cause != null) {
+ try {
+ DynConstructors.Ctor<? extends IOException> ctor =
+ new DynConstructors.Builder()
+ .impl(ioe.getClass(), String.class, Throwable.class)
+ .buildChecked();
+ newIoe = ctor.newInstance(node + ": " + ioe.getMessage(),
cause);
+ } catch (NoSuchMethodException e) {
+ // no matching constructor - try next approach below
+ }
+ }
+ if (newIoe == null) {
+ DynConstructors.Ctor<? extends IOException> ctor =
+ new DynConstructors.Builder()
+ .impl(ioe.getClass(), String.class)
+ .buildChecked();
+ newIoe = ctor.newInstance(node + ": " + ioe.getMessage());
+ if (cause != null) {
+ try {
+ newIoe.initCause(cause);
+ } catch (Exception e) {
+ // Unable to initCause. Ignore the exception.
+ }
+ }
+ }
newIoe.setStackTrace(ioe.getStackTrace());
Review Comment:
can this ever be null?
##########
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java:
##########
@@ -846,14 +846,36 @@ private T runWithRetry() throws IOException {
node = url.getAuthority();
}
try {
- IOException newIoe = ioe.getClass().getConstructor(String.class)
- .newInstance(node + ": " + ioe.getMessage());
- newIoe.initCause(ioe.getCause());
+ final Throwable cause = ioe.getCause();
+ IOException newIoe = null;
+ if (cause != null) {
+ try {
+ DynConstructors.Ctor<? extends IOException> ctor =
+ new DynConstructors.Builder()
+ .impl(ioe.getClass(), String.class, Throwable.class)
+ .buildChecked();
+ newIoe = ctor.newInstance(node + ": " + ioe.getMessage(),
cause);
+ } catch (NoSuchMethodException e) {
+ // no matching constructor - try next approach below
+ }
+ }
+ if (newIoe == null) {
+ DynConstructors.Ctor<? extends IOException> ctor =
+ new DynConstructors.Builder()
+ .impl(ioe.getClass(), String.class)
+ .buildChecked();
+ newIoe = ctor.newInstance(node + ": " + ioe.getMessage());
+ if (cause != null) {
+ try {
+ newIoe.initCause(cause);
+ } catch (Exception e) {
+ // Unable to initCause. Ignore the exception.
+ }
+ }
+ }
newIoe.setStackTrace(ioe.getStackTrace());
ioe = newIoe;
- } catch (NoSuchMethodException | SecurityException
- | InstantiationException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException e) {
+ } catch (NoSuchMethodException | SecurityException |
IllegalArgumentException e) {
Review Comment:
should we just catch all throwables here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]