Groovy - WARNING: An illegal reflective access operation has occurred
Asked Answered
L

9

50

I am pretty much new to java and groovy. I have installed groovy 3.0 on my windows 10 laptop (64 bit) and when tried to run groovy getting following warning:

>groovy -v
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/C:/groovy-3.0.0-alpha-1/lib/groovy-3.0.0-alpha-1.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
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
Groovy Version: 3.0.0-alpha-1 JVM: 9.0.1 Vendor: Oracle Corporation OS: Windows 10

And the java version is:

java --version
java 9.0.1
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

Any help to resolve this.

Laconia answered 22/12, 2017 at 4:15 Comment(10)
It's not an error, it's a warning. Won't hurt you.Clishmaclaver
Does it works without any issues going forward ? Is there any way to sort out this ?Laconia
It'll cause issues at some point in the future, but not yet. As the message says, you can report this to the library maintainers... if you're using the latest version, and a bug report doesn't already exist.Clishmaclaver
Groovy is having to undergo significant changes to accommodate the Java 9 module system; this is why the version is labeled alpha-1. If you're new to Groovy and Java, start with Groovy 2.4 (and probably Java 8) to get acquainted before dealing with modules.Ingather
@chrylis: Sure, will proceed as suggested.Laconia
I hope it may be ignored for now because it is warning nor error. Please se upstream bugreport for that: issues.apache.org/jira/browse/GROOVY-8339Birchfield
I am getting this error with Groovy v2.4.15 under JDK 1.8 -- I've seen several comments citing Java 9. I get it from 1.8, 10 and 11 (I skipped 9 just like Oracle did).Karimakarin
I have the same when using Java 11. Using Java 8 does not show this warning.Picturesque
"If you think something's supposed to hurt, you're less likely to notice if you're doing it wrong." -- Paul Graham. @shmosel: sure, a warning won't directly stop something from working, but making a habit of ignoring warnings is... I'd argue... "doing it wrong". Things shouldn't generate warnings unless someone is supposed to actually pay attention to them. And then if a warning is generated, we should actually pay attention. The fact that this is not a norm that's widely practiced does hurt various people in various ways, some big, mostly small (like wasted time here!)Restitution
2024 still going strong, will that ever be looked at?Interlocutress
B
9

To disable the warnings you can pass --add-opens to the JVM, see details here. Unfortunately Groovy requires a lot of modules/packages to be opened, see this (currently reverted) commit (source). Just tested these with AdoptOpenJDK 11.

Bumbledom answered 27/2, 2019 at 11:46 Comment(0)
B
8

It is more than a 'warning' for me: I cannot get Groovy scripts to run (on macOS) with the current JVM 9, much less 10. The workaround (until a compatible version of Groovy is available) is to install jenv and an earlier version of Java, so you can switch when needed.

Bracy answered 11/6, 2018 at 21:20 Comment(1)
The reason it might not work is explained here. Basically, Java changed some runtime rules that break/prevent Groovy's introspection of some private methods. superuser.com/a/1438336/331605Gogetter
R
5

Setting JAVA_HOME to a Version 8 JRE solved it for me:

#! /usr/bin/env -S JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre groovy
println "hello world"
Ricks answered 25/9, 2020 at 13:7 Comment(0)
A
4

Although my environment is Linux, after struggling some days to setup Groovy on Grails environment I feel like I know the answer: use JDK 8 for now. I was fiddling with JDK 9, and I thought it was too far behind so I tried JDK 11, which made things even worse, I got actual crashes. It seems like that Groovy / Grails is heavily lagging behind in terms of Java version compatibility.

Once the new Groovy will be released (said to be end of this year) then newer JDK can be used as well.

Almswoman answered 29/12, 2018 at 21:7 Comment(0)
H
2

Use the Java 8, however, if the java version must be 9 or >, you need to update the groovy version too.

I was running groovy 2.2.1 and it only works until java version 8

Hysteric answered 18/2, 2020 at 15:12 Comment(0)
D
1

add groovy-version to your pom:

        <groovy.version>3.0.4</groovy.version>
Donatist answered 25/5, 2020 at 3:21 Comment(3)
How come that this misleading hint got two points? Yes, it may work iff (a) Maven is used and (b) groovy's version is indirectly specified as ${groovy.version}.Blowzed
Btw, I'm using groovy-3.0.7.jar and java 11 (graal vm) and problem is still around.Blowzed
I am using jdk8 with maven, my groovy version was nowhere specified but adding this to my pom.xml solved the issue for me: <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy</artifactId> <version>3.0.8</version> </dependency>Fabio
H
1

I had this issue with openjdk 11.0.15 2022-04-19 and Groovy 2.4.17 on Linux Mint 20.1

WARNING: All illegal access operations will be denied in a future release
Groovy Version: 2.4.17 JVM: 11.0.15 Vendor: Private Build OS: Linux

To fix it I installed Jabba https://github.com/shyiko/jabba

First you need to set which version of Jabba you want to install:

export JABBA_VERSION=0.11.2

Then run the curl command:

curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | bash && . ~/.jabba/jabba.sh
Installing v0.11.2...

Adding source string to /home/spock/.bashrc
Adding source string to /home/spock/.profile
Installation completed
spock@hp-compaq-a:~/workspace/test/groovy-examples/hello-world$ jabba
Java Version Manager (https://github.com/shyiko/jabba).

Usage:
  jabba [flags]
  jabba [command]

Available Commands:
  install     Download and install JDK
  uninstall   Uninstall JDK
  link        Resolve or update a link
  unlink      Delete a link
  use         Modify PATH & JAVA_HOME to use specific JDK
  current     Display currently 'use'ed version
  ls          List installed versions
  ls-remote   List remote versions available for install
  deactivate  Undo effects of `jabba` on current shell
  alias       Resolve or update an alias
  unalias     Delete an alias
  which       Display path to installed JDK
spock@hp-compaq-a:~/workspace/test/groovy-examples/hello-world$ jabba ls
[email protected]

spock@hp-compaq-a:~/workspace/test/groovy-examples/hello-world$ jabba use [email protected]

spock@hp-compaq-a:~/workspace/test/groovy-examples/hello-world$ jabba current
[email protected]

spock@hp-compaq-a:~/workspace/test/groovy-examples/hello-world$ groovy -v
Groovy Version: 2.4.17 JVM: 1.8.0_275 Vendor: Azul Systems, Inc. OS: Linux

See this video for a good concise introduction to what Jabba can do:

https://www.youtube.com/watch?v=y2kYVCCeIMo

Horsefaced answered 8/7, 2022 at 20:29 Comment(1)
I like the idea of jabba. The underlying reason that it Groovy breaks is due to changes in the Java runtime, explained here superuser.com/a/1438336/331605.Gogetter
M
0

In my case it was because I was using JUNIT 5 with groovy but the latest supported I found is JUNIT 4.13

Marinara answered 5/1, 2021 at 12:12 Comment(0)
D
-1

It's not bug & it will be not affect to your project....dont worry....it is the just normal warning

Decaffeinate answered 21/5, 2024 at 11:48 Comment(1)
The other answers and comments already say the same thing as your answer and more than once, so what does your answer provide that does not already appear in the other answers?Shipe

© 2022 - 2025 — McMap. All rights reserved.