Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8140530

Creating a VolatileImage with size 0,0 results in no longer working g2d.drawString

    Details

    • Subcomponent:
      2d
    • Resolved In Build:
      b100
    • CPU:
      x86_64
    • OS:
      linux_ubuntu

      Backports

        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 ----------

          Issue Links

            Activity

            Hide
            scfitch Stephen Fitch added a comment -
            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.
            Show
            scfitch Stephen Fitch added a comment - 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.
            Hide
            pardesha Pardeep Sharma added a comment -
            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.
            Show
            pardesha Pardeep Sharma added a comment - 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.
            Hide
            pardesha Pardeep Sharma added a comment -
            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,
            >
            > ...........
            ==========================================================
            Show
            pardesha Pardeep Sharma added a comment - 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, > > ........... ==========================================================
            Hide
            psadhukhan Prasanta Sadhukhan added a comment -
            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.
            Show
            psadhukhan Prasanta Sadhukhan added a comment - 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.
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/client/jdk/rev/313b0c722ffe
            User: azvegint
            Date: 2015-12-04 10:57:21 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/client/jdk/rev/313b0c722ffe User: azvegint Date: 2015-12-04 10:57:21 +0000
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/313b0c722ffe
            User: lana
            Date: 2016-01-06 20:14:31 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/313b0c722ffe User: lana Date: 2016-01-06 20:14:31 +0000
            Hide
            aivanov Alexey Ivanov added a comment -
            The fix caused two regressions:
                • JDK-8147077
                • JDK-8148127

            See also JDK-8162836.
            Show
            aivanov Alexey Ivanov added a comment - The fix caused two regressions:     • JDK-8147077     • JDK-8148127 See also JDK-8162836 .
            Hide
            gsrinivassan Govindan Srinivassan added a comment -
            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?
            Show
            gsrinivassan Govindan Srinivassan added a comment - 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?
            Hide
            aivanov Alexey Ivanov added a comment -
            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.
            Show
            aivanov Alexey Ivanov added a comment - 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.

              People

              • Assignee:
                psadhukhan Prasanta Sadhukhan
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: