You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "Hiroshi Ikeda (JIRA)" <ji...@apache.org> on 2012/08/23 03:27:42 UTC

[jira] [Created] (HBASE-6639) Class.newInstance() can throw any checked exceptions and must be encapsulated with catching Exception

Hiroshi Ikeda created HBASE-6639:
------------------------------------

             Summary: Class.newInstance() can throw any checked exceptions and must be encapsulated with catching Exception
                 Key: HBASE-6639
                 URL: https://issues.apache.org/jira/browse/HBASE-6639
             Project: HBase
          Issue Type: Bug
    Affects Versions: 0.94.1
            Reporter: Hiroshi Ikeda
            Priority: Minor


There are some logics to call Class.newInstance() without catching Exception,
for example, in the method CoprocessorHost.loadInstance().

Class.newInstance() is declared to throw InstantiationException and IllegalAccessException but indeed the method can throw any checked exceptions without declaration.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (HBASE-6639) Class.newInstance() can throw any checked exceptions and must be encapsulated with catching Exception

Posted by "Zhihong Ted Yu (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HBASE-6639?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13440056#comment-13440056 ] 

Zhihong Ted Yu commented on HBASE-6639:
---------------------------------------

Looks like there is more than one place where Exception is not caught:
{code}
      o = implClass.newInstance();
./hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java
      HLog.Reader reader = logReaderClass.newInstance();
      HLog.Writer writer = (HLog.Writer) logWriterClass.newInstance();
      return keyClass.newInstance();
./hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java
          key = keyClass.newInstance();
./hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceFileLogReader.java
{code}
                
> Class.newInstance() can throw any checked exceptions and must be encapsulated with catching Exception
> -----------------------------------------------------------------------------------------------------
>
>                 Key: HBASE-6639
>                 URL: https://issues.apache.org/jira/browse/HBASE-6639
>             Project: HBase
>          Issue Type: Bug
>    Affects Versions: 0.94.1
>            Reporter: Hiroshi Ikeda
>            Priority: Minor
>
> There are some logics to call Class.newInstance() without catching Exception,
> for example, in the method CoprocessorHost.loadInstance().
> Class.newInstance() is declared to throw InstantiationException and IllegalAccessException but indeed the method can throw any checked exceptions without declaration.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (HBASE-6639) Class.newInstance() can throw any checked exceptions and must be encapsulated with catching Exception

Posted by "Hiroshi Ikeda (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HBASE-6639?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Hiroshi Ikeda updated HBASE-6639:
---------------------------------

    Attachment: HBASE-6639.patch

Added a patch.
Encapsulated with catching Exception, with fixing/refactoring some code.
                
> Class.newInstance() can throw any checked exceptions and must be encapsulated with catching Exception
> -----------------------------------------------------------------------------------------------------
>
>                 Key: HBASE-6639
>                 URL: https://issues.apache.org/jira/browse/HBASE-6639
>             Project: HBase
>          Issue Type: Bug
>    Affects Versions: 0.94.1
>            Reporter: Hiroshi Ikeda
>            Priority: Minor
>         Attachments: HBASE-6639.patch
>
>
> There are some logics to call Class.newInstance() without catching Exception,
> for example, in the method CoprocessorHost.loadInstance().
> Class.newInstance() is declared to throw InstantiationException and IllegalAccessException but indeed the method can throw any checked exceptions without declaration.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (HBASE-6639) Class.newInstance() can throw any checked exceptions and must be encapsulated with catching Exception

Posted by "Hiroshi Ikeda (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HBASE-6639?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13504360#comment-13504360 ] 

Hiroshi Ikeda commented on HBASE-6639:
--------------------------------------

Review board: https://reviews.apache.org/r/8230/
                
> Class.newInstance() can throw any checked exceptions and must be encapsulated with catching Exception
> -----------------------------------------------------------------------------------------------------
>
>                 Key: HBASE-6639
>                 URL: https://issues.apache.org/jira/browse/HBASE-6639
>             Project: HBase
>          Issue Type: Bug
>    Affects Versions: 0.94.1
>            Reporter: Hiroshi Ikeda
>            Priority: Minor
>         Attachments: HBASE-6639.patch
>
>
> There are some logics to call Class.newInstance() without catching Exception,
> for example, in the method CoprocessorHost.loadInstance().
> Class.newInstance() is declared to throw InstantiationException and IllegalAccessException but indeed the method can throw any checked exceptions without declaration.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (HBASE-6639) Class.newInstance() can throw any checked exceptions and must be encapsulated with catching Exception

Posted by "Zhihong Ted Yu (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HBASE-6639?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13440029#comment-13440029 ] 

Zhihong Ted Yu commented on HBASE-6639:
---------------------------------------

@Hiroshi:
Can you clarify your observation ?
See http://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Constructor.html#newInstance%28java.lang.Object...%29
                
> Class.newInstance() can throw any checked exceptions and must be encapsulated with catching Exception
> -----------------------------------------------------------------------------------------------------
>
>                 Key: HBASE-6639
>                 URL: https://issues.apache.org/jira/browse/HBASE-6639
>             Project: HBase
>          Issue Type: Bug
>    Affects Versions: 0.94.1
>            Reporter: Hiroshi Ikeda
>            Priority: Minor
>
> There are some logics to call Class.newInstance() without catching Exception,
> for example, in the method CoprocessorHost.loadInstance().
> Class.newInstance() is declared to throw InstantiationException and IllegalAccessException but indeed the method can throw any checked exceptions without declaration.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (HBASE-6639) Class.newInstance() can throw any checked exceptions and must be encapsulated with catching Exception

Posted by "Hiroshi Ikeda (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HBASE-6639?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13440055#comment-13440055 ] 

Hiroshi Ikeda commented on HBASE-6639:
--------------------------------------

Constructor.newInstance() avoids this problem.
Class.newInstance() is an exceptional method, and I think in almost all cases we must use try-catch to catch Exception, for example:

{code}
try {
  instance = clazz.newInstance();
} catch(Exception e) {
  ...
}
{code}

See http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#newInstance%28%29

For example you can fire any checked exceptions by the following code:
{code}
public class A {
    public static void fire(Exception e) {
        B.e = e;
        try { B.class.newInstance(); }
        catch (InstantiationException e1) {}
        catch (IllegalAccessException e1) {}
    }

    public static class B {
        static Exception e;
        public B() throws Exception { throw e; }
    }
}
{code}
                
> Class.newInstance() can throw any checked exceptions and must be encapsulated with catching Exception
> -----------------------------------------------------------------------------------------------------
>
>                 Key: HBASE-6639
>                 URL: https://issues.apache.org/jira/browse/HBASE-6639
>             Project: HBase
>          Issue Type: Bug
>    Affects Versions: 0.94.1
>            Reporter: Hiroshi Ikeda
>            Priority: Minor
>
> There are some logics to call Class.newInstance() without catching Exception,
> for example, in the method CoprocessorHost.loadInstance().
> Class.newInstance() is declared to throw InstantiationException and IllegalAccessException but indeed the method can throw any checked exceptions without declaration.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (HBASE-6639) Class.newInstance() can throw any checked exceptions and must be encapsulated with catching Exception

Posted by "Hiroshi Ikeda (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HBASE-6639?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Hiroshi Ikeda updated HBASE-6639:
---------------------------------

    Attachment: HBASE-6639-V2.patch

Patch v2 from review board.
                
> Class.newInstance() can throw any checked exceptions and must be encapsulated with catching Exception
> -----------------------------------------------------------------------------------------------------
>
>                 Key: HBASE-6639
>                 URL: https://issues.apache.org/jira/browse/HBASE-6639
>             Project: HBase
>          Issue Type: Bug
>    Affects Versions: 0.94.1
>            Reporter: Hiroshi Ikeda
>            Priority: Minor
>         Attachments: HBASE-6639.patch, HBASE-6639-V2.patch
>
>
> There are some logics to call Class.newInstance() without catching Exception,
> for example, in the method CoprocessorHost.loadInstance().
> Class.newInstance() is declared to throw InstantiationException and IllegalAccessException but indeed the method can throw any checked exceptions without declaration.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira