IllegalAccessException after updating 2.1 to 2.2
richard.bair at oracle.com
Fri Aug 17 07:49:24 PDT 2012
Lets try to get this into 2.2.2?
On Aug 17, 2012, at 5:52 AM, Greg Brown wrote:
> Sorry about this. I thought that this had been fixed before the 2.2 release, but it was not. A similar issue was raised a while back with respect to injection of the "location" and "resources" fields. If a legacy class defined one of these fields and was not properly annotated, injection would fail. This was fixed such that FXMLLoader now ignores IllegalAccessException when injecting those fields, but I did not think to make a similar change for the initialize() method.
> Can you please file a bug report? Thanks.
> On Aug 16, 2012, at 11:51 AM, Werner Lehmann <lehmann at media-interactive.de> wrote:
>> 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...
More information about the openjfx-dev