sshahine / JFoenix

JavaFX Material Design Library
MIT License
6.27k stars 1.05k forks source link

Jfoenix dependency illegal reflective access with java 11 #1170

Open alittwin opened 3 years ago

alittwin commented 3 years ago

WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by com.jfoenix.adapters.ReflectionHelper (file:/C:/Users/Albon/.m2/repository/com/jfoenix/jfoenix/9.0.10/jfoenix-9.0.10.jar) to method java.lang.reflect.AccessibleObject.setAccessible0(boolean) WARNING: Please consider reporting this to the maintainers of com.jfoenix.adapters.ReflectionHelper 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

I get this error while trying to load an fxml parent with jfoenix components. Application still works after this problem, but i'm not sure if i should just ignore it because i'm making a bigger project. Do you know what could cause it and how to fix it?

sshahine commented 3 years ago

Well, it's because JFoenix is using reflection to access some private methods/fields of the original JavaFX controls. To fix this issue, some changes need to be done from JavaFX side to allow more flexibility in customizing the controls. Till that happens, not much we can do.

m0squito commented 3 years ago

Does it mean that it could potentially become incompatible with a future release of JavaFX? Or do you expect that a future release will open up the API?

sshahine commented 3 years ago

I doubt that would happen anytime soon, cause there are so many libraries dependent on java reflection. But in any case, I'll create a ticket for JavaFX to open up some internal API.

Ulathar commented 3 years ago

Having a similar problem: java.lang.IllegalAccessException: class com.jfoenix.skins.JFXTextFieldSkin (in module com.jfoenix) cannot access a member of class javafx.scene.control.skin.TextFieldSkin (in module javafx.controls) with modifiers "private"

Already tried adding --illegal-access=warn --add-opens javafx.controls/javafx.scene.control.skin=com.jfoenix --add-opens java.base/java.lang.reflect=com.jfoenix

as JRE JVM Runtimeparameter as well as Maven Options without success. Running on AdoptOpenJDK 11.0.10.9-openj9.

What is the right way to handle this? Especially looking forward to upcomming JDK releases.

RocketMaDev commented 2 years ago

Could anyone tell me which class caused this warning? I want to try to fix it. (Low possibility to work it out)

louhy commented 2 years ago

@RocketMaDev You'd probably have to set a breakpoint in it to see the full picture (I'm sure it depends on what component you're using), but if you mean the ReflectionHelper class mentioned in the OP (which maybe you couldn't find)... it's only in the 9.0.0 branch (not master).

https://github.com/sshahine/JFoenix/blob/JFoenix-9.0.0/jfoenix/src/main/java/com/jfoenix/adapters/ReflectionHelper.java

But you'd probably have to look for or open (if one doesn't exist) a ticket for JavaFX itself as noted above...

louhy commented 2 years ago

Actually I'm not sure if this can be fixed without some drastic measures, this static block is the first one hit, and there's lots of other calls to setAccessible below in ReflectionHelper. Doesn't look too promising for a fix without a lot of work.

/**
 * This class is for breaking the module system of Java 9.
 *
 * @author huang
 */
public class ReflectionHelper {

//    private static Unsafe unsafe = null;
//    private static long objectFieldOffset;
    private static Method accessible0;

    static {
        try {
//            unsafe = AccessController.doPrivileged((PrivilegedExceptionAction<Unsafe>) () -> {
//                Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
//                theUnsafe.setAccessible(true);
//                return (Unsafe) theUnsafe.get(null);
//            });
//            Field overrideField = AccessibleObject.class.getDeclaredField("override");
//            objectFieldOffset = unsafe.objectFieldOffset(overrideField);
            accessible0 = AccessibleObject.class.getDeclaredMethod("setAccessible0", boolean.class);
            accessible0.setAccessible(true);
        } catch (Throwable ex) {
            ex.printStackTrace();
        }
    }
Pramudz commented 1 year ago

did anyone come up with any solution for this ?

louhy commented 1 year ago

did anyone come up with any solution for this ?

I don't think there's really any "one" solution, it depends on the error. There's a few other issues filed here about it. Also I've read that there's a more modern version of this library: https://github.com/palexdev/MaterialFX (Haven't tried it yet.)