JDK-8158178 : java.awt.SplashScreen.getSize() returns incorrect size for high dpi splash screens
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8u92
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: other
  • CPU: x86
  • Submitted: 2016-05-23
  • Updated: 2016-10-13
  • Resolved: 2016-06-07
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 8 JDK 9
8u112Fixed 9 b124Fixed
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Darwin saotome.local 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
When a high-dpi splashscreen is available (e.g. splash.png and splash@2x.png), the SplashScreen#getSize() and SplashScreen#getBounds methods return an incorrect size.

This is most likely caused by an incorrect implementation of the SplashScreen#getBounds method when the scale factor is applied:

            if (scale > 0 && scale != 1) {
                bounds.setSize((int) (bounds.getWidth() / scale),
                        (int) (bounds.getWidth() / scale));
            }


This should become

            if (scale > 0 && scale != 1) {
                bounds.setSize((int) (bounds.getWidth() / scale),
                        (int) (bounds.getHeight() / scale));
            }

Regression was introduced in this commit: http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/4fa603c72f2f

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- Compile the attached class (SplashScreenTest)
- Create a non-square regular and retina splash screen image (e.g. https://raw.githubusercontent.com/JetBrains/intellij-community/master/community-resources/src/idea_community_about.png and https://raw.githubusercontent.com/JetBrains/intellij-community/master/community-resources/src/idea_community_about%402x.png)
- Run the application on a high-dpi device (e.g. a recent Macbook) and specify the splash screen using -splash:path/to/splash.png

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The reported width and height of the splash screen are not the same, as the source image is a non-square image
ACTUAL -
The reported width and height of the splash screen are the same

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.SplashScreen;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;

public class SplashScreenTest {
  public static void main(String[] args) throws Exception{
    SplashScreen splashScreen = SplashScreen.getSplashScreen();
    Dimension size = splashScreen.getSize();
    System.out.println("size = " + size);
    if ( (size.getWidth() == size.getHeight())){
      throw new RuntimeException("Width and height of the splash screen are the same, which shouldn't be the case");
    }
    Thread.sleep(2000);
    EventQueue.invokeLater(new Runnable() {
      @Override
      public void run() {
        showUI();
      }
    });
  }

  private static void showUI(){
    JFrame frame = new JFrame("Test");
    frame.getContentPane().add(new JLabel("Label"));
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.setVisible(true);
  }
}

---------- END SOURCE ----------


Comments
The issue is resolved in the fix JDK-8145174 But the proposed test can be contributed under this bug id. See discussion: http://mail.openjdk.java.net/pipermail/awt-dev/2016-May/011380.html Webrev: http://cr.openjdk.java.net/~alexsch/robin.stevens/8158178/webrev.00/
30-05-2016