IllegalAccessException after updating 2.1 to 2.2
Werner Lehmann
lehmann at media-interactive.de
Thu Aug 16 08:51:20 PDT 2012
Hi,
today I updated from 2.1 to 2.2 - and received an exception during FXML
loading which was not present in 2.1. Apparently the 2.2 loader looks
for an "initialize" method in the controller and its super classes. In
my case it finds a protected initialize() in a legacy super class which
is used in Swing. Later on it fails to invoke that initialize() because
it is not made accessible (having no @FXML annotation, of course).
> Caused by: javafx.fxml.LoadException: java.lang.IllegalAccessException: Class javafx.fxml.FXMLLoader can not access a member of class mint.panel.MintContextPanel with modifiers "protected"
> at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2184)
> at mint.javafx.MintFXUtils.loadWithController(MintFXUtils.java:86)
> ... 8 more
> Caused by: java.lang.IllegalAccessException: Class javafx.fxml.FXMLLoader can not access a member of class mint.panel.MintContextPanel with modifiers "protected"
> at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2182)
> ... 9 more
As a workaround I renamed the initialize() method to something
completely different and that worked. But I'd rather not have to do
this. It is legacy code, and there are several extending classes
overriding the protected method.
Also, if the existing method in the super class was public already,
FXMLLoader would have called initialize() unexpectedly.
Looking at the code change from 2.1 to 2.2 this seems to be done
intentionally: now the code looks for any no-args initialize method via
reflection if Initializable is not implemented, thus breaking backward
compatibility.
Can we just require the non-interfaced initialize() method to be
annotated with @FXML? That would clearly document the FX related
intention for a very common method name...
Rgds
Werner
More information about the openjfx-dev
mailing list