JDK-8316741 : BasicStroke.createStrokedShape miter-limits failing on small shapes
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 20,21,22
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2023-09-21
  • Updated: 2023-10-24
  • Resolved: 2023-10-21
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 22
22 masterFixed
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Linux / OpenJDK 64-Bit Server VM (build 21+35-2513, mixed mode, sharing)


A DESCRIPTION OF THE PROBLEM :
The below source code is expected to create a sharp point at the join of the two lines, and does in all versions of the JVM from about Java through Java 19

In Java 21 the point is being rounded.

It looks to be related to the fact that the shape is very small but drawn through an AffineTransform, and it looks to be related to createStrokedShape: if I simple draw the path, I get a sharp point.

REGRESSION : Last worked in version 19

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached, look at the output file "out.png"

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A sharp point
ACTUAL -
A round point

---------- BEGIN SOURCE ----------
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.imageio.*;

public class Test {
    public static void main(String[] args) throws Exception {
        // Gives incorrect results in Java 21, correct in Java 19 and earlier.
        BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = image.createGraphics();
        g.setPaint(Color.WHITE);
        g.fillRect(0, 0, 100, 100);
        g.setPaint(Color.BLACK);
        g.setTransform(new AffineTransform(100, 0, 0, 100, 0, 0));
        BasicStroke stroke = new BasicStroke(0.1f, 0, 0, 10);
        Path2D p = new Path2D.Float();
        p.moveTo(1, 0.2f);
        p.lineTo(0.4f, 0.4f);
        p.lineTo(1, 0.6f);
        Shape outline = stroke.createStrokedShape(p);
        g.fill(outline);
        g.dispose();
        ImageIO.write(image, "png", new File("out.png"));
    }
}

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

FREQUENCY : always



Comments
[jdk21u-fix-request] Approval Request from Laurent Bourgès "fix regression introduced in jdk20, not present in jdk17"
21-10-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk21u/pull/279 Date: 2023-10-21 09:35:12 +0000
21-10-2023

Changeset: a876beb6 Author: Laurent Bourgès <lbourges@openjdk.org> Date: 2023-10-21 09:12:08 +0000 URL: https://git.openjdk.org/jdk/commit/a876beb63d5d509b80366139ae4c6abe502efe1e
21-10-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/16002 Date: 2023-10-01 20:33:54 +0000
01-10-2023

I will have a look to diagnose this regression
22-09-2023

Regression of JDK-8297230. I see the old behavior after reverting it.
22-09-2023

Checked with attached testcase in Windows and Ubuntu 20.04, Issue is reproducible, <attached screenshot for reference> Test Result ========== jdk8u381: Pass jdk11.0.20: Pass jdk17.0.8: Pass jdk19.0.2: Pass jdk20 b24: Pass jdk20 b25: Fail <- Regression jdk21 Fail jdk22ea16: Fail
22-09-2023