You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2023/05/30 18:32:00 UTC
[jira] [Comment Edited] (GROOVY-11075) The method pointer operator suppresses checked exceptions and results in a MethodMissingException
[ https://issues.apache.org/jira/browse/GROOVY-11075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17727645#comment-17727645 ]
Eric Milles edited comment on GROOVY-11075 at 5/30/23 6:31 PM:
---------------------------------------------------------------
Your example method does not declare that it throws any checked exceptions, so Groovy must be wrapping the {{IOException}} in an unchecked exception before the method returns.
It is here where the exception propagates as InvokerInvocationException and it falls to some additional handling. This would not be the case for non-static methods. https://github.com/apache/groovy/blob/f1aef96fed3d8911afba1d160ce07ff085e14dc2/src/main/java/groovy/lang/MetaClassImpl.java#L1003
was (Author: emilles):
Your example method does not declare that it throws any checked exceptions, so Groovy must be wrapping the {{IOException}} in an unchecked exception before the method returns.
> The method pointer operator suppresses checked exceptions and results in a MethodMissingException
> -------------------------------------------------------------------------------------------------
>
> Key: GROOVY-11075
> URL: https://issues.apache.org/jira/browse/GROOVY-11075
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 4.0.12
> Reporter: Joe Li
> Priority: Major
>
> The method pointer operator suppresses checked exceptions and results in a MethodMissingException instead in groovy 4.0.12. This issue seems to first appear in groovy 3.0.16, which is the earliest version I am able to reproduce. Example code
> {code:java}
> class Foo {
> static void bar(String str) {
> throw new IOException()
> println str
> }
> }
> def baz = Foo.&bar
> baz('hi') {code}
> This results in a MethodMissingException despite the IO Exception being thrown. This seems to be the case for any checked exception.
>
> {code:java}
> class Foo {
> static void bar(String str) {
> throw new IOException()
> println str
> }
> }
> Foo.bar("hi") {code}
> When calling the method directly I get an IO Exception as expected
--
This message was sent by Atlassian Jira
(v8.20.10#820010)