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

Jochen Theodorou commented on GROOVY-11116:
-------------------------------------------

This stretches the "optional" for that optional quite a bit. Why does a 
reference to an optional dependency have to occur in a method signature? If the 
reference is done in the method body there is no problem. I am actually 
surprised this passes class loading in the JVM. My assumption is the Groovy 
fails for this at runtime and at compile time. Compile time might be solvable, 
then it could work with compile static till a meta class is created for that, 
and that can happen any time. Fixing the issue at meta class level is 
difficult, since the initialization would have to be reworked completely.

> Groovy does not handle missing classes gracefully like Java does
> ----------------------------------------------------------------
>
>                 Key: GROOVY-11116
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11116
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.21, 3.0.15, 4.0.9
>            Reporter: Björn Kautler
>            Priority: Major
>
> When executing the snippet
> {code}
> @Grab('club.minnced:discord-webhooks:0.8.2')
> import club.minnced.discord.webhook.WebhookClientBuilder
> new WebhookClientBuilder(1, "").setWait(false)
> {code}
> Groovy fails with a {{ClassNotFoundException}}.
> Also using {{@CompileStatic}} does not help it just changes the thrown error 
> a bit.
> When Groovy tries to initialize the members of {{WebhookClientBuilder}}, it 
> tries to initialize internal method representations for all methods.
> Some of the methods use classes in their signature that are optional for that 
> library.
> From Java this works perfectly fine as long as you don't use any of the 
> methods that need those optional dependencies.
> But in Groovy, this does not work, as Groovy always tries to read all methods 
> fully.
> It would be nice if Groovy could be made more lenient here and only fail if 
> one of the methods with missing dependencies is actually tried to be used.
> The only work-around I found is using the {{WebhookClientBuilder}} only from 
> a Java class that is then used from the Groovy code



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to