Bug 1124374 - Graphics2D.drawLine() wrongly draws the first point
Summary: Graphics2D.drawLine() wrongly draws the first point
Keywords:
Status: CLOSED INSUFFICIENT_DATA
Alias: None
Product: Fedora
Classification: Fedora
Component: java-1.7.0-openjdk
Version: 21
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Deepak Bhole
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-07-29 11:19 UTC by Julien Gouesse
Modified: 2014-08-05 12:17 UTC (History)
6 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2014-07-31 10:50:22 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
diagonal cross wrongly drawn (225 bytes, image/png)
2014-07-29 11:19 UTC, Julien Gouesse
no flags Details
test 1 (131 bytes, image/png)
2014-07-29 19:14 UTC, Julien Gouesse
no flags Details
test 2 (176 bytes, image/png)
2014-07-29 19:15 UTC, Julien Gouesse
no flags Details
test 3 (1.58 KB, image/png)
2014-07-29 19:22 UTC, Julien Gouesse
no flags Details
c8 result (2.42 KB, image/png)
2014-07-30 11:13 UTC, jiri vanek
no flags Details

Description Julien Gouesse 2014-07-29 11:19:05 UTC
Description of problem:
I try to draw a diagonal cross and I get a different result with the same code under Microsoft Windows with Oracle Java 1.7 update 60 (expected result) and under Fedora Linux 21 (under Mageia Linux 4 too) with OpenJDK 1.7 update 60 (wrong result).

Version-Release number of selected component (if applicable):
1.7 update 60

How reproducible:
Always

Steps to Reproduce:
1. Compile and run the following test case:
import java.awt.BasicStroke;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.SwingUtilities;


public class Test {

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			
			@Override
			public void run() {
				Frame frame=new Frame();
				frame.add(new Canvas(){
					private static final long serialVersionUID = 1L;

					@Override
					public void paint(Graphics g){
						final Graphics2D g2=(Graphics2D)g.create();
			            g2.setStroke(new BasicStroke(1.0f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER));
			            g2.setColor(Color.BLACK);
			            final int delta=3;
			            final int width=20;
			            final int height=20;
			            g2.drawLine(delta,delta,width-delta-1,height-delta-1);
			            g2.drawLine(width-delta-1,delta,delta,height-delta-1);
			            g2.dispose();
					}
				});
				frame.setSize(600,600);
				frame.addWindowListener(new WindowAdapter() {
					@Override
					public void windowClosing(WindowEvent we) {
						System.exit(0);
					}
				});
				frame.setVisible(true);
			}
		});
	}
}


Actual results:
The drawing goes beyond the first and the last points.
See the enclosed image.

Expected results:
A line is drawn between the first and the last point of each line.

Additional info:
I can't login on OpenJDK bug tracker, that's why I'm posting it here.

Comment 1 Julien Gouesse 2014-07-29 11:19:36 UTC
Created attachment 922112 [details]
diagonal cross wrongly drawn

Comment 2 Julien Gouesse 2014-07-29 11:21:07 UTC
I tried to disable the Java2D pipeline based on XRender with -Dsun.java2d.xrender=false and the anti-aliasing (by using the rendering hint) but it didn't help.

Comment 3 jiri vanek 2014-07-29 13:03:49 UTC
Hi!

I'm not able to reproduce on latest jdk.
java version "1.7.0_65"
OpenJDK Runtime Environment (fedora-2.5.1.3.fc20-x86_64 u65-b17)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
on my fedora.

However the Fedora is not shiping icedtea, so it can cause.

Anyway - this is rewritten your reproducer, to exclude some possibel side effects of gui:
package crossestest;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;


public class CrossesTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        BufferedImage i1 = new BufferedImage(46, 24, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = i1.createGraphics();
        g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
        g2.setColor(Color.BLACK);
        final int delta = 3;
        final int width = 20;
        final int height = 20;
        g2.drawLine(delta, delta, width - delta - 1, height - delta - 1);
        g2.drawLine(width - delta - 1, delta, delta, height - delta - 1);
        g2.dispose();
        ImageIO.write(i1, "png", new File(System.getProperty("user.home")+"/Desktop/i1.png"));
    }

}

Does it have same corrupted behaviour?

Also, this one is getting rid of cusotm Stroke:

package crossestest;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;


public class CrossesTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        BufferedImage i1 = new BufferedImage(46, 24, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = i1.createGraphics();
        g2.setColor(Color.blue);
        g2.drawRect(1 ,1, 21, 21);
        g2.drawLine(3,3, 20,20);
        g2.drawLine(3,20, 20,3);
        g2.dispose();
        ImageIO.write(i1, "png", new File(System.getProperty("user.home")+"/Desktop/i1.png"));
    }

}



Does it also fail for you?

Comment 4 Julien Gouesse 2014-07-29 13:57:47 UTC
I'll give a try to your code at home. How could the absence or the presence of icedtea affect the rendering?

Comment 5 Julien Gouesse 2014-07-29 19:14:12 UTC
Your two test cases don't fail.
java version "1.7.0_65"
OpenJDK Runtime Environment (mageia-2.5.1.1.mga4-x86_64 u65-b17)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)

Comment 6 Julien Gouesse 2014-07-29 19:14:49 UTC
Created attachment 922292 [details]
test 1

Comment 7 Julien Gouesse 2014-07-29 19:15:11 UTC
Created attachment 922293 [details]
test 2

Comment 8 Julien Gouesse 2014-07-29 19:21:58 UTC
This test fails but it shows the problems seems to come from the last point :s See i3.png

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.SwingUtilities;


public class Test {

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			
			@Override
			public void run() {
				Frame frame=new Frame();
				frame.add(new Canvas(){
					private static final long serialVersionUID = 1L;

					@Override
					public void paint(Graphics g){
						final Graphics2D g2=(Graphics2D)g.create();
			            g2.setColor(Color.blue);
			            g2.drawRect(1 ,1, 21, 21);
			            g2.drawLine(3,3, 20,20);
			            g2.drawLine(3,20, 20,3);
			            g2.dispose();
					}
				});
				frame.setSize(600,600);
				frame.addWindowListener(new WindowAdapter() {
					@Override
					public void windowClosing(WindowEvent we) {
						System.exit(0);
					}
				});
				frame.setVisible(true);
			}
		});
	}
}

Comment 9 Julien Gouesse 2014-07-29 19:22:32 UTC
Created attachment 922296 [details]
test 3

Comment 10 jiri vanek 2014-07-30 11:13:31 UTC
Created attachment 922488 [details]
c8 result

hm.. I'm still not bale to reproduce. Attache dis result of comment 8 application

Comment 11 jiri vanek 2014-07-30 11:21:03 UTC
package crossestest;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class CrossesTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        int c = 0;
        for (int x1 = 1; x1 <= 22; x1++) {
            for (int x2 = 1; x2 <= 22; x2++) {
                for (int y1 = 1; y1 <= 22; y1++) {
                    for (int y2 = 1; y2 <= 22; y2++) {
                        c++;
                        BufferedImage im = new BufferedImage(23, 23, BufferedImage.TYPE_INT_ARGB);
                        Graphics2D g2 = im.createGraphics();
                        //g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
                        g2.setColor(Color.red);
                        g2.drawLine(x1, y1, x2, y2);
                        g2.dispose();
                        int i1 = im.getRGB(x1, y1);
                        int i2 = im.getRGB(x2, y2);
                        Color c1 = new Color(i1);
                        Color c2 = new Color(i2);
                        if (!c1.equals(Color.RED) || !c2.equals(Color.red)) {
                            System.out.println("Failed for "+x1+", "+y1+", "+x2+", "+y2+"");
                            ImageIO.write(im, "png", new File(System.getProperty("user.home") + "/Desktop/i" + c + ".png"));
                        } else {
                           // System.out.println(c + " passed for "+x1+", "+y1+", "+x2+", "+y2+"");
                        }
                    }
                }
            }
        }
    }

}


Can you try this?

If it will pass for you we can be sure it is issue ow swing. However, I'm really unhappy I can not repreoduce. Can you post more about your system?

I have fedora 20,  mate, with default window manager.
Now I'm  trying  it also on  other fedoras and other window managers and other jdks.

Comment 12 Julien Gouesse 2014-07-30 13:05:00 UTC
How can it be an issue of Swing whereas my first example doesn't use it (only AWT)? I'll test your example when I'm at home in some hours as usual.

Comment 13 jiri vanek 2014-07-30 13:56:01 UTC
Sorry. I was unclear. I ment generally UI java interface or underlying native code.

Comment 14 Julien Gouesse 2014-07-30 21:40:36 UTC
Your latest test prints nothing. It seems to confirm your hypothesis. Should I report this bug against Mageia Linux 4?

Comment 15 Julien Gouesse 2014-07-31 08:40:14 UTC
I have installed the source RPM of OpenJDK "devel", I'll debug the latest test and another one exhibiting the bug on my machine at home. I'll let you know my findings.

Comment 16 jiri vanek 2014-07-31 10:50:22 UTC
I had run your reproducer on:
 rhel7 64b  - jdk6
 rhel7 64b  - jdk7
 rhel7 64b  - jdk8
   - always gnome3+hnome shell and fluxbox
 f20 32b - jdk7
  -  fluxbox and mate
 f20 64b - jdk7
  - cinamon, xfce, mate, openbox, kde(4?), gnome shell


And they shown correctly. On gnome shell I had funny issue that during repaint, not always not everything was flushed. Eg only square was painted but not the cross. After more investigions on this issue I come to conclusion that it is not bug.


So yes. I would ask you to fill thebug against Mageia - https://bugs.mageia.org/ ?

I'm closing now as insufficient data. Please feel free to reopen if Mageia guys  will find some jdk cause. Please also attach the lik to magiea bug.

maybe if you will share more detaisl about your environment I will be able to reproduce.

Comment 17 Julien Gouesse 2014-08-03 17:03:42 UTC
Do you think I should install java-1.7.0-openjdk-1.7.0.65-2.5.1.3.fc20.x86_64.rpm under Mageia in order to see how it behaves? I know it isn't very clean.

Comment 18 Julien Gouesse 2014-08-03 19:26:29 UTC
Bug reported against Mageia:
https://bugs.mageia.org/show_bug.cgi?id=13850

Investigation in progress, workaround found, possible root cause found.

Comment 19 jiri vanek 2014-08-05 08:13:55 UTC
I'm seriously looking forward to see the results!

Comment 20 Julien Gouesse 2014-08-05 12:17:49 UTC
I didn't succeed in installing the Fedora packages under Mageia because of missing dependencies.

The bug is probably in the native source code of the old X11 pipeline. As the XRender pipeline is enabled by default on Java 1.8 and not concerned by this bug, I won't fix it, I won't waste any time in fixing a bug in a pipeline that is going to be "replaced".


Note You need to log in before you can comment on or make changes to this bug.