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

Double.NaN isn't handled gracefully

XMLWordPrintable

    • 2d
    • generic
    • generic

      Bugzilla submission:

      NotANumberTest: Double.NaN isn't handled gracefully when stroking shapes.
      -------------NotANumberTest.java------------------
      import java.awt.*;
      import java.awt.geom.Path2D;
      import java.awt.image.BufferedImage;
      import java.io.File;
      import javax.imageio.ImageIO;

      /**
       * @author ###@###.### (Chris Nokleberg)
       * @author ###@###.### (Hiroshi Yamauchi)
       */
      public class NotANumberTest {
        public static void main(String[] args) throws Exception {
          BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
          Graphics2D g = image.createGraphics();

          g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          g.setPaint(Color.WHITE);
          g.fill(new Rectangle(image.getWidth(), image.getHeight()));

          Path2D path = new Path2D.Double();
          path.moveTo(25.0, 25.0);
          path.lineTo(175.0, 25.0);
          path.lineTo(175.0, 175.0);
          path.lineTo(Double.NaN, Double.NaN);
          path.lineTo(25.0, 175.0);
          path.lineTo(25.0, 25.0);

          g.setPaint(Color.BLUE);
          g.fill(path);

          // To visually check it
          //ImageIO.write(image, "PNG", new File(args[0]));

          boolean nonWhitePixelFound = false;
          for (int y = 125; y < 200; ++y) {
            if (image.getRGB(100, y) != Color.WHITE.getRGB()) {
              nonWhitePixelFound = true;
              break;
            }
          }
          if (!nonWhitePixelFound) {
            throw new RuntimeException("NaN isn't gracefully handled by Path2D.");
          }
        }
      }

            Unassigned Unassigned
            jgodinez Jennifer Godinez (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: