Hi,

The relaxed permissions, which are allowed given the default '--illegal-access=permit' mode, only apply to modules that are linked into the Java runtime. Modules that are loaded on the module-path are subject to strict access controls.

I see three possible solutions for you:

1. Run your application with 'java --add-opens javafx.controls/javafx.scene.control=ALL-UNNAMED' 2. jlink the javafx modules into a custom JRE (at which point the javafx modules are part of the java runtime) 3. Find a solution that doesn't rely on accessing internal implementation details of javafx.controls.

I note that the default for --illegal-access is likely to change to "deny" in the not-too-distant future -- possibly as early as JDK 12, so it is only a matter of time before this will affect platform classes (at which time option #2 stops being available without adding '--illegal-access=permit').

Long-term you should explore #3, since accessing internal fields or methods is fragile and might stop working at any point.

-- Kevin


On 7/24/2018 4:44 AM, [email protected] wrote:

below is a small app that comes up with a button: on click it wants
to access a private field (obviouly via reflection) in the button class.
Due to relaxed permission constraints, that works in all java versions 9/10 without additional configuration and also with openjdk for non-fx classes.

With the combination of openjdk10 + openjfx-ea (both downloaded from their respective download pages at java.net) it throws an error at runtime on clicking:

Exception in thread "JavaFX Application Thread"
java.lang.reflect.InaccessibleObjectException:
Unable to make field private javafx.beans.property.BooleanProperty
javafx.scene.control.Button.defaultButton accessible:
module javafx.controls does not "opens javafx.scene.control" to unnamed module @b65246

Happens both from the command line (thanks Johan for the concise example,
easy to understand even for a command line hater like myself :) as from inside eclipse

Any idea what's wrong?


public class MinimalAccessFieldFX10Open extends Application {

    private Parent getContent() {
        Button button = new Button("something to click on");

        button.setOnAction(e -> {
            // okay
            Object def = invokeGetFieldValue(Button.class, button, "defaultButton");
            LOG.info("getting the private field: " + def);
        });
        BorderPane pane = new BorderPane(button);
        return pane;
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setScene(new Scene(getContent(), 600, 400));
        primaryStage.show();
    }

    public static Object invokeGetFieldValue(Class<?> declaringClass,
            Object target, String name) {
        try {
            Field field = declaringClass.getDeclaredField(name);
            field.setAccessible(true);
            return field.get(target);
        } catch (NoSuchFieldException | SecurityException
                | IllegalArgumentException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        launch(args);
    }

    @SuppressWarnings("unused")
    private static final Logger LOG = Logger
.getLogger(MinimalAccessFieldFX10Open.class.getName());
}


Reply via email to