[ 
https://issues.apache.org/jira/browse/GROOVY-7821?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15253330#comment-15253330
 ] 

Paul King commented on GROOVY-7821:
-----------------------------------

The Groovy compiler essentially converts the above code into:
{code}
try {
    throw new java.lang.NullPointerException('ahh!')
} 
catch (java.lang.NullPointerException e) {
    // ... logging stmts
} 
catch (java.io.IOException e) {
    // ... logging stmts
} 
{code}
and on the 2_4_X branch the generated bytecode for the logging stmts looks like:
{code}
CHECKCAST java/io/IOException
INVOKEVIRTUAL java/io/IOException.getMessage ()Ljava/lang/String;
INVOKEINTERFACE org/slf4j/Logger.error (Ljava/lang/String;Ljava/lang/Object;)V
{code}
for both(!) branches whereas in master the generated code is:
{code}
INVOKEVIRTUAL java/lang/Throwable.getMessage ()Ljava/lang/String;
INVOKEINTERFACE org/slf4j/Logger.error (Ljava/lang/String;Ljava/lang/Object;)V
{code}


> @CompileStatic and exception list throws ClassCastException
> -----------------------------------------------------------
>
>                 Key: GROOVY-7821
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7821
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.6
>         Environment: OSX, java version "1.8.0_40"
>            Reporter: Brendon Anderson
>            Priority: Minor
>
> {code:title=Bar.java|borderStyle=solid}
> @Slf4j
> @CompileStatic
> class TestException {
>     static void main(String[] args) {
>         try {
>             throw new NullPointerException('ahh!')
>         } catch (NullPointerException | IOException e) {
>             log.error('error {}', e.message)
>         }
>     }
> }
> {code}
> This throws a ClassCastException:
> {noformat}
> Exception in thread "main" java.lang.ClassCastException: 
> java.lang.NullPointerException cannot be cast to java.io.IOException
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to