JDK-8149967 : Cannot compile JFXPanel with JDK 9: SurfaceData::getDefaultScale not found
  • Type: Bug
  • Component: javafx
  • Sub-Component: swing
  • Affected Version: 9
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-02-16
  • Updated: 2016-02-17
  • Resolved: 2016-02-17
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.
JDK 9
9Fixed
Related Reports
Blocks :  
Relates :  
Relates :  
Description
Compiling FX with a recent build of JDK 9 gives the following error:

$ java -version
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+105-2016-02-10-235300.javare.4433)
Java HotSpot(TM) Client VM (build 9-ea+105-2016-02-10-235300.javare.4433, mixed mode)

$ gradle
...
/localhome/kcr/javafx/9-kcr/jfx/rt/modules/swing/src/main/java/javafx/embed/swing/JFXPanel.java:692: error: cannot find symbol
                newScaleFactor = ((SunGraphics2D)g).surfaceData.getDefaultScale();
                                                               ^
  symbol: method getDefaultScale()
  location: variable surfaceData of type SurfaceData

This is a result of changes to the sun.java2d.SurfaceData class for Windows Hi-DPI support -- see JDK-8073320. This class used to have a getDefaultScale() method and now has separate getDefaultScaleX() and getDefaultScaleY() methods.

Comments
Changeset: d5312b49f9ad Author: kcr Date: 2016-02-17 07:25 -0800 URL: http://hg.openjdk.java.net/openjfx/9-dev/rt/rev/d5312b49f9ad 8149967: Cannot compile JFXPanel with JDK 9: SurfaceData::getDefaultScale not found Reviewed-by: flar
17-02-2016

I filed JDK-8150064 as a follow-up issue.
17-02-2016

I considered this, and would do it if we weren't planning to switch to JDK 9 soon. As it is, the fallback would be very short-lived, so I thought I would save the effort of testing it (coding it up would be trivial). I will file a follow-up issue to remove the reflection code and provide a suitable replacement.
17-02-2016

I guess it would only be for testing where I imagine a number of engineers are still running FX9 on JDK8 (particularly since that is still the bootstrap JDK), but should it call the old method if the new method fails (or vice versa)?
16-02-2016

Webrev: http://cr.openjdk.java.net/~kcr/8149967/webrev.00/ Proposed fix is as described above. I tested this on Windows (without Hi-DPI enabled) and on a Mac retina (scale factor of 2).
16-02-2016

Note that this bug is causing NoSuchMethodError at runtime when running any JFXPanel application using the promoted JDK 9 builds, since the method in question is no longer there.
16-02-2016

Easy short term fix: we can call the new getDefaultScaleX() method using reflection, and default to 1.0 if it is not found. Once we have switched to JDK 9 as the boot JDK, we can remove the reflection and call the new method directly. We can then also decide what, if anything, we need to do if the X and Y scales are different.
16-02-2016