Openjfx ea: error on trying to access private fields
fastegal at swingempire.de
fastegal at swingempire.de
Tue Jul 24 11:44:00 UTC 2018
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());
}
More information about the openjfx-dev
mailing list