JFoenix icon indicating copy to clipboard operation
JFoenix copied to clipboard

Jfoenix dependency illegal reflective access with java 11

Open alittwin opened this issue 4 years ago • 9 comments

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?

alittwin avatar Dec 14 '20 15:12 alittwin

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.

sshahine avatar Dec 16 '20 21:12 sshahine

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?

m0squito avatar Jan 27 '21 20:01 m0squito

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.

sshahine avatar Jan 31 '21 11:01 sshahine

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.

Ulathar avatar Feb 15 '21 11:02 Ulathar

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

RocketMaDev avatar Oct 30 '21 11:10 RocketMaDev

@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 avatar Nov 10 '21 07:11 louhy

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();
        }
    }

louhy avatar Nov 11 '21 02:11 louhy

did anyone come up with any solution for this ?

Pramudz avatar Jun 12 '23 16:06 Pramudz

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.)

louhy avatar Jun 17 '23 01:06 louhy