[
https://issues.apache.org/jira/browse/GROOVY-10391?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17453424#comment-17453424
]
Eric Milles commented on GROOVY-10391:
--------------------------------------
To handle the "negate()" call, Groovy runtime is running through this in
{{org.codehaus.groovy.vmplugin.v9.Java9}}:
{code:java}
public Object getInvokeSpecialHandle(Method method, Object receiver) {
final Class<?> receiverType = receiver.getClass();
try {
return of(receiverType).unreflectSpecial(method,
receiverType).bindTo(receiver);
} catch (ReflectiveOperationException e) {
return super.getInvokeSpecialHandle(method, receiver);
}
}
{code}
{{receiver}} is an instance of "script$_run_closure1@3d5c822d" which is the
result of your closure coercion. {{receiverType}} is {{jdk.proxy1.$Proxy5}}
and this is where the access check is reporting that "jdk.proxy1" is not
available to the unnamed module.
In this case of calling an interface default method, it may be possible to
choose a different receiver class using the method's declaring class. I also
have to see how Groovy 4 is handling the situation.
> Default interface methods causing problems with java 17 and groovy 3.0.9
> ------------------------------------------------------------------------
>
> Key: GROOVY-10391
> URL: https://issues.apache.org/jira/browse/GROOVY-10391
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 3.0.9
> Environment: jdk 17.0.1 corretto
> gradle 7.3
> groovy 3.0.9
> Reporter: Łukasz Pieróg
> Priority: Major
> Fix For: 4.0.0-beta-2
>
>
> I'm trying to migrate a project to build on JDK17 and in that project we use
> groovy and spock for testing. It seems that groovy 3.* has a problem with
> reflection access to JDK especially visible when using closures
> A simple test class:
> {code:java}
> static void main(String[] args) {
> def predicate = {true} as java.util.function.Predicate
> predicate.negate()
> println "i don't work!! :("
> } {code}
> Produces
> {noformat}
> java.lang.IllegalAccessException: module jdk.proxy1 does not open jdk.proxy1
> to unnamed module @43517800{noformat}
> In line
> {code:java}
> predicate.negate() {code}
> .negate() being a default method in a Predicate interface which a part of the
> jdk
> The following however works:
> {code:java}
> static void main(String[] args) {
> def predicate = new Predicate() {
> @Override
> boolean test(Object o) {
> true
> }
> }
> predicate.negate()
> println "i work!! :)"
> } {code}
> I'm using JDK 17.0.1 Corretto for my tests and the example minimal project
> can be found here:
> [https://github.com/lukaszpierog/jdk17-groovy3]
> The above code works with groovy 4.0.0-beta-2. Spock does not support groovy
> 4 at this moment, so upgrading groovy to 4 isn't an option for me and it
> seems to only be a beta release at the moment.
> I've tried adding jvm args
> --add-opens=java.base/java.lang.invoke=ALL-UNNAMED
> however that does not seem to affect the output
> Please advise
--
This message was sent by Atlassian Jira
(v8.20.1#820001)