JDK-8165373 : Ensemble8 uses setAccessible to access methods and fields of various classes
  • Type: Bug
  • Component: javafx
  • Sub-Component: samples
  • Affected Version: 9
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-09-02
  • Updated: 2020-01-31
  • Resolved: 2016-09-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
8u152Fixed 9Fixed
Related Reports
Blocks :  
The PlaygroundTab.update method  in Ensemble8 uses setAccessible to access methods and fields of various classes. It does this blindly, both on application classes (which is fine), and on JavaFX classes (which is not good practice), without any indication as to whether it is needed.

This is not a good practice so the setAccessible calls should be removed. If any loss of functionality occurs we will need to evaluate the impact.
Webrev for 8u backport: http://cr.openjdk.java.net/~kcr/Ensemble8/separate/11-8165373/webrev/

This is part of an aggregate backport request to port Ensemble8 fixes from FX 9 to FX 8u. See JDK-8168611 for details and review.

Changeset: 62d65bc20537 Author: kcr Date: 2016-09-10 06:41 -0700 URL: http://hg.openjdk.java.net/openjfx/9-dev/rt/rev/62d65bc20537 8165373: Ensemble8 uses setAccessible to access methods and fields of various classes Reviewed-by: vadim


http://cr.openjdk.java.net/~kcr/8165373/webrev.01/ Fixed as indicated above. 1. Removed the code that looped through the field names looking for a private property of that name, leaving only the code that accesses the xxxxProperty method. 2. Added public xxxxProperty methods to the 4 samples listed above.

There are only four such samples, so I will fix these by adding the appropriate public xxxxxProperty() methods. Controls --> Text --> TextFormatter Graphics_2d --> Images --> Image Operation Graphics_3d --> 3D Sphere Media --> Aplha Media Player

I ran through all the samples, and the second method is also used for internal properties in at least one of the Ensemble applications. I will either need to find and fix them all by adding an xxxProperty method for each property we want to access (that is the cleanest), or possibly keep the old buggy code as a fallback. The former is a better option and avoids keeping the bogus setAccessible code.

There are two calls to setAccessible in the Ensemble PlaygroundTabs class. One of them is used to access internal data from a Sample object within Ensemble itself. That access is fine -- it could be made cleaner, but there is no harm in leaving it alone. The second place is in a very dubious block of code that tries to look for the private property field of the desired name in the given JavaFX class to access the property in question. If no such field is found in the JavaFX class, then it does the right thing and looks for a method of that name with "Property" concatenated to the end. Many properties already use the correct "fallback" code of looking up the public *Property method because the (bad) code that looks for the named private field will only find it if it is the class itself but not in any superclass. The solution is to just remove this unnecessary (and wrong) block of code and always use the correct mechanism of accessing the public *Property method. This both fixes the problem and is has the benefit of being correct.