JDK-8066193 : Drawing Rectangle in Java 8 Shows Pixel Anomaly. Prior version 7 is OK
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8u25
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2014-11-12
  • Updated: 2014-11-30
  • Resolved: 2014-11-30
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
Java Version 8

ADDITIONAL OS VERSION INFORMATION :
Windows 7 Professional 64 BIT

EXTRA RELEVANT SYSTEM CONFIGURATION :
Lenovo Thinkpad T440

A DESCRIPTION OF THE PROBLEM :
I have a very simple java program that draws a rectangle but when I closely examine the rendered shape, I see two extra pixels that shouldn't be there

http://stackoverflow.com/questions/22058987/drawing-rectangle-in-java-shows-pixel-anomaly?rq=1

ADDITIONAL REGRESSION INFORMATION: 
Any version prior to Version 8 works, at least with my Lenovo Thinkpad T440


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Please refer to source code

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I was expecting to see a closed Rectangle 
ACTUAL -
The rectangle is off by one pixel on the bottom right and bottom left (looks like an off-by-one pixel bug). Please fix this as it was working in prior version

ERROR MESSAGES/STACK TRACES THAT OCCUR :
None ... See link  for screenshot

http://stackoverflow.com/questions/22058987/drawing-rectangle-in-java-shows-pixel-anomaly?rq=1

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Graphics;
    import java.io.IOException;
    import javax.swing.JFrame;
    import javax.swing.JPanel;

    public class JavaBug {

    public JavaBug() throws IOException {
        JFrame frame = new JFrame();        
        frame.add( new JPanel() {
        private static final long serialVersionUID = 1L;

                public void paintComponent( Graphics g ) {
                    super.paintComponent(g);
                    g.drawRect(50, 50, 20, 20); 
                }
            });

            frame.setSize(400, 300);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible( true );
        }

        public static void main(String [] args) throws IOException {
            new JavaBug();
        }
    }
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
draw rectangle with individual lines 


Comments
Looks to me like a dup of https://bugs.openjdk.java.net/browse/JDK-8049901 Try -Dsun.java2d.d3d=false Note that 8u40 will disable d3d on Intel so this (should) go away then.
30-11-2014

Response from the submitter: "I just checked again and I see the issue. It is very hard to see as it is off by just one pixel on the bottom corners. I have attached a blow up screenshot to show you. I posted this bug a long time ago on stackoverflow site when version 8 was still not released. I was hoping the bug would not make it to release 8 but it did. http://stackoverflow.com/questions/22058987/drawing-rectangle-in-java-shows-pixel-anomaly I have confirmed on my machine this problem goes away in version 7. Can you not simply compare the code between 7 and 8 for the Graphics.drawRect()function? Others have seen this bug as mentioned in stackoverflow and others say it works which is very odd. Please let me know how I can help you further with this bug. I will be happy to help."
29-11-2014

Unable to reproduce this with JDK 7u72, 8u25 and JDK 9ea on Windows 7 Pro. Written to the original submitter to reconfirm the issue status. Resolving this as incomplete for now.
28-11-2014