Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings with Java 9 #64

Open
zedaster opened this issue Aug 16, 2018 · 15 comments
Open

Warnings with Java 9 #64

zedaster opened this issue Aug 16, 2018 · 15 comments

Comments

@zedaster
Copy link

zedaster commented Aug 16, 2018

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.esotericsoftware.reflectasm.AccessClassLoader (file:/C:/Users/Сергей/.m2/repository/com/esotericsoftware/reflectasm/1.11.7/reflectasm-1.11.7.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.esotericsoftware.reflectasm.AccessClassLoader
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
@rarcher
Copy link

rarcher commented Oct 5, 2018

Some of my users are also seeing this. See rarcher/couch-potato-server#27 for a discussion.

@magro
Copy link
Collaborator

magro commented Jan 1, 2019

An option might be to create a multi release jar (aka MRJAR) and use a different way for Java 9+ to defineClass (MethodHandles.Lookup.defineClass).

@TheMode
Copy link

TheMode commented Aug 25, 2019

Any update?

@NathanSweet
Copy link
Member

Can ignore or disable the warning.

@cowwoc
Copy link

cowwoc commented Aug 25, 2019

@NathanSweet Obviously. But can't the underlying problem be fixed?

@NathanSweet
Copy link
Member

I'm not sure, I haven't looked into it. It's not a problem yet though, it's just a warning. It won't be a problem until they disallow what the library needs to function. At that time we either fix it or the library won't work on the latest JVMs. That is the case for a great many libraries.

@cowwoc
Copy link

cowwoc commented Aug 26, 2019

@NathanSweet For what it's worth, @magro explained how to fix this problem. Simply replace ClassLoader.defineClass with MethodHandles.Lookup.defineClass

@NathanSweet
Copy link
Member

If that works, great! I just haven't had the time or personal need to dig into it.

@jfida
Copy link

jfida commented Sep 30, 2019

Any news on this?

@thawkins
Copy link

thawkins commented Nov 1, 2019

I'm running into this too, any idea of when a fix may be available.

@iverhun
Copy link

iverhun commented Feb 4, 2020

Just FYI: still the same warning with java 13

@magro
Copy link
Collaborator

magro commented Apr 4, 2020

Sorry I'm too busy with other things, but maybe someone could come up with a PR for multi-release jar?

robinverduijn added a commit to robinverduijn/reflectasm that referenced this issue Apr 5, 2020
Try to use MethodHandles.lookup().defineClass() instead of ClassLoader.defineClass(), as suggested on EsotericSoftware#64
This will get rid of the following warnings:

```
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.esotericsoftware.reflectasm.AccessClassLoader (file:/.m2/repository/com/esotericsoftware/reflectasm/1.11.7/reflectasm-1.11.7.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.esotericsoftware.reflectasm.AccessClassLoader
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
```

Although as it is, these changes break some of the unit tests, with failures like the following:

```
java.lang.LinkageError: loader 'app' attempted duplicate class definition for com.esotericsoftware.reflectasm.ClassLoaderTest$Test. (com.esotericsoftware.reflectasm.ClassLoaderTest$Test is in unnamed module of loader 'app')
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.System$2.defineClass(System.java:2126)
	at java.base/java.lang.invoke.MethodHandles$Lookup.defineClass(MethodHandles.java:962)
	at com.esotericsoftware.reflectasm.ClassLoaderTest$TestClassLoader1.loadClass(ClassLoaderTest.java:162)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	at com.esotericsoftware.reflectasm.ClassLoaderTest.testRemoveClassloaders(ClassLoaderTest.java:99)
```
@robinverduijn
Copy link

I tried to implement the suggestion of using MethodHandles.lookup().defineClass() instead of ClassLoader.defineClass(), but only got as far as robinverduijn/reflectasm@fix-code-warnings...robinverduijn:fix-illegal-reflective-access. It left me with the warning gone but two tests failing. At that point I got stuck, but maybe someone else can figure out how to make it work from there?

@dwing4g
Copy link

dwing4g commented Nov 4, 2020

try this:

// suppress "An illegal reflective access operation has occurred" in JDK9+
if (!System.getProperty("java.version").startsWith("1.") && !MethodAccess.class.getModule().isNamed())
Class.class.getModule().addOpens(Class.class.getPackageName(), MethodAccess.class.getModule());

@soundasleep
Copy link

soundasleep commented Aug 10, 2021

In a similar vein to EsotericSoftware/kryo#626, could you support a System property (-Dreflectasm.unsafe=false) or something so that we can stop this error message from appearing (and ideally start to get ready for when illegal access is removed)? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests