35

When I run Groovy 2.5.3 on JDK 11 its giving warning message:

groovy -e 'print "hi"'
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/home/user/.sdkman/candidates/groovy/current/lib/groovy-2.5.3.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Is there an option to disable this warning message?

catch23
  • 17,519
  • 42
  • 144
  • 217
sfgroups
  • 18,151
  • 28
  • 132
  • 204
  • 3
    It seems that there's open PR for this issue: https://github.com/apache/groovy/pull/811/ – Opal Oct 22 '18 at 14:11
  • @Opal Thanks looks like I have to wait for another groovy release. – sfgroups Oct 22 '18 at 15:58
  • 9
    You can set the `GROOVY_TURN_OFF_JAVA_WARNINGS` environment variable to `true` until we fix the underlying code. – Paul King Oct 23 '18 at 05:15
  • 1
    Thanks Paul, now its giving another warning `WARNING: package sun.awt.windows not in java.desktop` – sfgroups Oct 23 '18 at 12:51
  • 2
    I presume you are on *nix? Can you try removing "--add-opens=java.desktop/sun.awt.windows=ALL-UNNAMED" from your startGroovy shell script. It's needed when on MS Windows OS but we haven't made it conditional when it finds it is on cygwin or similar. – Paul King Mar 06 '19 at 04:36
  • now warning message gone. Thanks Paul. – sfgroups Mar 07 '19 at 02:05
  • @PaulKing I see that the PR has been merged, can you advise which stable release for groovy has the fix for this issue? – Phalgun May 28 '19 at 11:33
  • 2
    @phalgun Perhaps this update will help you: https://opencollective.com/friends-of-groovy/updates/progressing-towards-groovy-3-0-0-with-greatly-reduced-illegal-access-errors – Paul King May 28 '19 at 19:56

4 Answers4

2

You can disable the Java warnings with GROOVY_TURN_OFF_JAVA_WARNINGS as a temporary fix:

$ GROOVY_TURN_OFF_JAVA_WARNINGS=true groovy -e 'print "hi\n"'
hi
kba
  • 19,333
  • 5
  • 62
  • 89
2

This is still an issue in Groovy 2.5.8

I'm on macOS. I chose to fall back to Java 8 (In homebrew, do a brew cask install adoptopenjdk8) and the warnings went away. I understand that is is not desirable if you need a newer JDK (I do not)

catch23
  • 17,519
  • 42
  • 144
  • 217
msuhovecky
  • 21
  • 1
2

The current stable version 3.0.x of Groovy is reported to fix this issue, see GROOVY-8339 for the detailed discussion.

centic
  • 15,565
  • 9
  • 68
  • 125
0

To disable warnings either by upgrading groovy version to large than 3.0.0 or by passing --add-opens to the JVM. unfortunately it requires a lot of modules to be opened check the following commit