jMonkeyEngine / jmonkeyengine

A complete 3-D game development suite written in Java.
http://jmonkeyengine.org
BSD 3-Clause "New" or "Revised" License
3.81k stars 1.12k forks source link

Illegal reflective access in com.jme3.util.ReflectionAllocator #1085

Open assofohdz opened 5 years ago

assofohdz commented 5 years ago

When running my game on my work station (not when running it on my laptop), I get the follow error:

WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by com.jme3.util.ReflectionAllocator (file:/C:/Users/asser/AppData/Roaming/itch/apps/Subspace%20Infinity/libs/jme3-core-3.2.3-stable.jar) to method sun.nio.ch.DirectBuffer.cleaner() WARNING: Please consider reporting this to the maintainers of com.jme3.util.ReflectionAllocator 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

assofohdz commented 5 years ago

This file: https://github.com/jMonkeyEngine/jmonkeyengine/blob/d57c362ec3b510c1ba6356f719efa3b1576b95c6/jme3-core/src/main/java/com/jme3/util/ReflectionAllocator.java

stephengold commented 5 years ago

How can we reproduce the warning?

assofohdz commented 5 years ago

I was running latest stable jme at the time, but with java 11. After changing to java 8 I did not experience the issue any more.

empirephoenix commented 5 years ago

This is no real wonder, as the ReflectiveAllocator works by using questionable hacks. If you are actually worried about it, you could use a different one, eg the lwjgl based one.

stephengold commented 5 years ago

This issue recently started showing up in the Travis openjdk11 build. Here is the context:

> Task :jme3-core:processTestResources
> Task :jme3-core:testClasses
> Task :jme3-core:test
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.jme3.util.ReflectionAllocator (file:/home/travis/build/jMonkeyEngine/jmonkeyengine/jme3-core/build/classes/java/main/) to method sun.nio.ch.DirectBuffer.cleaner()
WARNING: Please consider reporting this to the maintainers of com.jme3.util.ReflectionAllocator
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
stephengold commented 5 years ago

We could make PrimitiveAllocator the default instead of ReflectionAllocator. One drawback is that PrimitiveAllocator can't actually destroy direct buffers, so there could be other runtime warnings (to System.err) and a greater likelihood of running out of buffers.

stephengold commented 5 years ago

@tlf30 I know you use Java 11. Have you encountered this issue?

tlf30 commented 5 years ago

Yes, all of my apps have these errors all over with jme. It is not an issue right now, just a warning. I has to do with the fact that future versions of Java will deny reflection access if a module does not explicitly give it permission. This can be fixed by creating a module definition for jme. It is something that has been on my Todo list for a while.

pspeed42 commented 5 years ago

Yes, JME (especially networking but other places, too) will need reflective access.

Ali-RS commented 5 years ago

Regarding sun.nio.ch.DirectBuffer.cleaner()

WARNING: Illegal reflective access by com.jme3.util.ReflectionAllocator (file:/home/travis/build/jMonkeyEngine/jmonkeyengine/jme3-core/build/classes/java/main/) to method sun.nio.ch.DirectBuffer.cleaner()

there is an alternative way for Java 9+: https://bugs.openjdk.java.net/browse/JDK-8171377

https://github.com/diffplug/matfilerw/issues/16#issuecomment-434623867

https://github.com/HebiRobotics/MFL/blob/68c5f02feda27023bed19d72fbdc5f41e31f9804/mat-file-io/src/main/java/us/hebi/matlab/common/memory/NativeMemory.java

Edit: And https://github.com/rrd4j/rrd4j/commit/4b791a7ac03c26ff159f97fa0716c0d28aa15a45