Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10391

Default interface methods causing problems with java 17 and groovy 3.0.9

    XMLWordPrintableJSON

Details

    Description

      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:

      static void main(String[] args) {
          def predicate = {true} as java.util.function.Predicate
          predicate.negate()
          println "i don't work!! :("
      } 

      Produces

      java.lang.IllegalAccessException: module jdk.proxy1 does not open jdk.proxy1 to unnamed module @43517800

      In line

      predicate.negate() 

      .negate() being a default method in a Predicate interface which a part of the jdk

      The following however works:

      static void main(String[] args) {
          def predicate = new Predicate() {
              @Override
              boolean test(Object o) {
                  true
              }
          }
          predicate.negate()
          println "i work!! :)"
      } 

      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

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              lukaszpierog Łukasz Pieróg
              Votes:
              3 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: