JDK-8140530 : Creating a VolatileImage with size 0,0 results in no longer working g2d.drawString
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8u60
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux_ubuntu
  • CPU: x86_64
  • Submitted: 2015-08-27
  • Updated: 2017-01-11
  • Resolved: 2015-12-04
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 6 JDK 7 JDK 8 JDK 9 Other
6u131Fixed 7u121Fixed 8u111Fixed 9 b100Fixed openjdk7uFixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
 1.8.0_60

ADDITIONAL OS VERSION INFORMATION :
Linux augusta 3.19.0-26-generic #28-Ubuntu SMP Tue Aug 11 14:16:32 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

EXTRA RELEVANT SYSTEM CONFIGURATION :
NVIDIA Corporation GK104 [GeForce GTX 670]
Nvidia binary driver: nvidia-355


A DESCRIPTION OF THE PROBLEM :
When creating a VolatileImage with size 0/0 (which does not throw an exception), there are surprising side effect:

All texts drawn on a graphics context do not longer show up.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- Create a VolatileImage with size 0,0
- Draw a String on a graphics context (g2d.drawString)



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
IllegalArgumentException(?)
ACTUAL -
No exception is thrown.
Strings are no longer visible when using Graphics2D#drawString

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
 System.out.println("Java Version: " + System.getProperty("java.version"));

    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice device = env.getDefaultScreenDevice();

    //if size is set to 0 the string is not visible in Linux (with nvidia binary driver)
    int size = 0;
    VolatileImage volatileImage = device.getDefaultConfiguration().createCompatibleVolatileImage(size, size); //This image is never used


    JFrame frame = new JFrame();

    frame.getContentPane().add(new JComponent() {
      @Override
      protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        g.setColor(Color.RED);
        ((Graphics2D) g).drawString("Hello World", 10, 20);
      }
    });

    frame.setSize(800, 600);
    frame.setVisible(true);
---------- END SOURCE ----------


Comments
Govindan, After the fixes from JDK-8147077 and JDK-8148127 are applied, IAE is not thrown in the cases where either width=0 or height=0. So no change is required.
22-08-2016

It looks like the specification does not have explicit mentioning of IAE to be thrown when width=0 or height=0 http://download.java.net/java/jdk9/docs/api/java/awt/GraphicsConfiguration.html#createCompatibleVolatileImage-int-int- do we need to file ccc for jdk spec?
05-08-2016

The fix caused two regressions: ��� JDK-8147077 ��� JDK-8148127 See also JDK-8162836.
01-08-2016

The issue was creating a volatileImage with 0 width, height does not result in IllegalArgumentException. But, when we try to create a non-volatile Image via GraphicsConfiguration.createCompatibleImage(0,0) or a BufferedImage(0,0,imagetype) it results in IAE. So, to maintain consistency across all image w.r.t 0 width,height, createVolatileImage() should also throw IAE. In windows, creating a volatileImage with 0 width,height resulted in IAE but in linux it does not. This is because XCreatePixmap() generate BadValue unless width,height is nonzero but the error handler does not catch it https://tronche.com/gui/x/xlib/pixmap-and-cursor/XCreatePixmap.html [The width and height arguments must be nonzero, or a BadValue error results.] I have added a check to prevent zero width,height to be used for XCreatePixmap() and also throw OOME so to ask Java to throw IAE.
02-12-2015

Re-opened based upon submitter's new response: ========================================================= On 11/4/2015 2:04 AM, ....... wrote: > Hi ........, > > I have been able to reproduce the problem with > 1.8.0_66 and 1.9.0-ea-b81 > > A main class to reproduce the problem: > https://github.com/jschneider/jdk-bug-9063327/blob/develop/src/main/java/com/cedarsoft/BugDemo.java > > > Interestingly 1.7.0_04 throws an exception: > > Exception in thread "main" java.lang.IllegalArgumentException: Width (0) > and height (0) cannot be <= 0 > at > java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1016) > at > java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:149) > at > java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:178) > at sun.awt.image.SunVolatileImage.getBackupImage(SunVolatileImage.java:236) > at > sun.awt.image.VolatileSurfaceManager.getBackupSurface(VolatileSurfaceManager.java:263) > at > sun.awt.image.VolatileSurfaceManager.initialize(VolatileSurfaceManager.java:126) > at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:88) > at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:117) > at > java.awt.GraphicsConfiguration.createCompatibleVolatileImage(GraphicsConfiguration.java:307) > > > > Thanks, > > ........... ==========================================================
12-11-2015

Closing this as incomplete as we haven't received additional required information to proceed further. We may reopen this report if we receive any update in future.
26-10-2015

JI Team to ask filer if the issue reproduces with JDK 8u Latest and 9. https://jdk9.java.net/download/ Also need stand-alone/isolated reproducer.
08-10-2015