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

Alexander Kriegisch edited comment on GROOVY-10450 at 2/11/23 4:56 PM:
-----------------------------------------------------------------------

{quote}Yes, 3.0.15 was released on the 8th.{quote}

That is too bad, now I have to wait for another release cycle. The problem was 
from 3.0.9. I have a suggestion for next time, [~emilles], [~paulk]:
# I know, it took 4 calendar days for me to provide feedback, which is quick 
for a bug that was open for more than a year. But please, next time, wait for 
feedback before closing an issue and cutting a release.
# If a user is nice enough to provide a reproducer for his bug, please be so 
kind as to actually run it after you think the issue was fixed. Had you done 
this, you would have noticed that the fix/backport was still incomplete.

Either of 1 or 2 would have helped to avoid the problem we now have.

{quote}If you know of any other issues, please do open a ticket.{quote}

Yes, of course. For now, I am unaware of any related issues, but that does not 
mean a lot. I use Groovy kind of sporadically when writing Spock tests, mostly 
when answering Stack Overflow questions for fun or when coaching developers in 
test automation as an agile coach. I am not an active developer, 20+ years ago 
I earned my last money as a software developer and have been a consultant ever 
since. But thanks for bearing with a hobbyist.


was (Author: kriegaex):
{quote}Yes, 3.0.15 was released on the 8th.{quote}

That is too bad, now I have to wait for another release cycle. The problem was 
from 3.0.9. I have a suggestion for next time, [~emilles], [~paulk]:
# I know, it took 4 calendar days for me to provide feedback, which is quick 
for a bug that was open for more than a year. But please, next time, wait for 
feedback before closing an issue and cutting a release.
# If a user is nice enough to provide a reproducer for his bug, please be so 
kind as to actually run it after you think the issue was fixed. Had you don 
this, you would have noticed that the fix/backport was still incomplete.

Either of 1 or 2 would have helped to avoid the problem we now have.

{quote}If you know of any other issues, please do open a ticket.{quote}

Yes, of course. For now, I am unaware of any related issues, but that does not 
mean a lot. I use Groovy kind of sporadically when writing Spock tests, mostly 
when answering Stack Overflow questions for fun or coaching developers in test 
automation as an agile coach. I am not an active developer, 20+ years  ago I 
earned my last money as a software developer and have been a consultant ever 
since. But thanks for bearing with a hobbyist.

> Cannot call BiPredicate methods on closures or lambdas on JRE 16+
> -----------------------------------------------------------------
>
>                 Key: GROOVY-10450
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10450
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.9
>            Reporter: Alexander Kriegisch
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 3.0.15
>
>
> The issue was first discovered by a Spock user in 
> [Spock-1412|https://github.com/spockframework/spock/issues/1412].
> Under Groovy 3.0.9, the following code works on JREs 8-15, but starts failing 
> on 16+, possibly due to [JEP 396 (Strongly Encapsulate JDK Internals by 
> Default)|https://openjdk.java.net/jeps/396]:
> {code:groovy}
> import java.util.function.BiPredicate
> class CombineBiPredicatesAndClosures {
>   static void main(String[] args) {
>     println "Java version: ${System.properties['java.version']}"
>     // Old-school anonymous class instead of closure or lambda
>     /*
>     BiPredicate<String, Integer> bi = new BiPredicate<String, Integer>() {
>       @Override
>       boolean test(String domain, Integer score) {
>         return domain.equalsIgnoreCase("google.com")
>       }
>     }
>     */
>     // Lambda syntax only works in Groovy 3+
>     //BiPredicate<String, Integer> bi = (domain, score) -> 
> domain.equalsIgnoreCase("google.com")
>     //def bi2 = (domain, score) -> score == 11
>     // Closure syntax works in Groovy 2.5, too
>     BiPredicate<String, Integer> bi = { domain, score -> 
> domain.equalsIgnoreCase("google.com") }
>     def bi2 = { domain, score -> score == 11 }
>     def logicalNot = bi.negate()
>     assert logicalNot.test("acme.org", 11)
>     assert !logicalNot.test("google.com", 11)
>     def logicalOr = bi | bi2
>     assert logicalOr.test("google.com", 11)
>     assert logicalOr.test("google.com", 0)
>     assert logicalOr.test("x", 11)
>     assert !logicalOr.test("x", 0)
>     def logicalAnd = bi & bi2
>     assert logicalAnd.test("google.com", 11)
>     assert !logicalAnd.test("google.com", 0)
>     assert !logicalAnd.test("x", 11)
>     assert !logicalAnd.test("x", 0)
>   }
> }
> {code}
> Running the program yields something like:
> {code:none}
> Java version: 16
> Exception in thread "main" java.lang.reflect.InvocationTargetException
>       at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
>       at 
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.base/java.lang.reflect.Method.invoke(Method.java:567)
>       at org.codehaus.groovy.vmplugin.v9.Java9.of(Java9.java:160)
>       at 
> org.codehaus.groovy.vmplugin.v9.Java9.getInvokeSpecialHandle(Java9.java:179)
>       at 
> org.codehaus.groovy.runtime.ConversionHandler.lambda$invoke$0(ConversionHandler.java:97)
>       at 
> java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
>       at 
> org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:97)
>       at jdk.proxy1/jdk.proxy1.$Proxy9.negate(Unknown Source)
>       at java_util_function_BiPredicate$negate.call(Unknown Source)
>       at 
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
>       at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
>       at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
>       at 
> CombineBiPredicatesAndClosures.main(CombineBiPredicatesAndClosures.groovy:25)
> Caused by: java.lang.IllegalAccessException: module jdk.proxy1 does not open 
> jdk.proxy1 to unnamed module @153f5a29
>       at 
> java.base/java.lang.invoke.MethodHandles.privateLookupIn(MethodHandles.java:260)
>       ... 15 more
> {code}
> When running the same program on Groovy 4.0.0-rc-2, there are no problems on 
> JDK 16+. Using the commented-out anonymous class instead of either a lambda 
> or closure also works around the problem on Groovy 3.
> Could you please fix this for the next 3.0.x version? Thank you.



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

Reply via email to