[ 
https://issues.apache.org/jira/browse/HADOOP-16453?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Lisheng Sun updated HADOOP-16453:
---------------------------------
    Description: 
When there is no String Constructor for the exception, we Log a Trace Message. 
Given that log and throw is not a very good approach I think the right thing 
would be to just not log it at all as HADOOP-16431.
{code:java}
private static <T extends IOException> T wrapWithMessage(
    T exception, String msg) throws T {
  Class<? extends Throwable> clazz = exception.getClass();
  try {
    Constructor<? extends Throwable> ctor = clazz.getConstructor(String.class);
    Throwable t = ctor.newInstance(msg);
    return (T)(t.initCause(exception));
  } catch (Throwable e) {
    LOG.trace("Unable to wrap exception of type {}: it has no (String) "
        + "constructor", clazz, e);
    throw exception;
  }
}
{code}
 

  was:
private static <T extends IOException> T wrapWithMessage(
  T exception, String msg) {  Class<? extends Throwable> clazz = 
exception.getClass();  try {
    Constructor<? extends Throwable> ctor =
      clazz.getConstructor(String.class);
    Throwable t = ctor.newInstance(msg);    return (T) (t.initCause(exception));
  } catch (Throwable e) {
    LOG.trace("Unable to wrap exception of type " +
             clazz + ": it has no (String) constructor", e);    return 
exception;
  }
}


> Remove useless trace log in NetUtils.java
> -----------------------------------------
>
>                 Key: HADOOP-16453
>                 URL: https://issues.apache.org/jira/browse/HADOOP-16453
>             Project: Hadoop Common
>          Issue Type: Improvement
>            Reporter: Lisheng Sun
>            Assignee: Lisheng Sun
>            Priority: Minor
>
> When there is no String Constructor for the exception, we Log a Trace 
> Message. Given that log and throw is not a very good approach I think the 
> right thing would be to just not log it at all as HADOOP-16431.
> {code:java}
> private static <T extends IOException> T wrapWithMessage(
>     T exception, String msg) throws T {
>   Class<? extends Throwable> clazz = exception.getClass();
>   try {
>     Constructor<? extends Throwable> ctor = 
> clazz.getConstructor(String.class);
>     Throwable t = ctor.newInstance(msg);
>     return (T)(t.initCause(exception));
>   } catch (Throwable e) {
>     LOG.trace("Unable to wrap exception of type {}: it has no (String) "
>         + "constructor", clazz, e);
>     throw exception;
>   }
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to