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

REGRESSION: Rotating graphics2D to draw CJK string causes OutOfMemoryError

XMLWordPrintable

    • 2d
    • 5.0
    • b86
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      JDK1.5_0*

      ADDITIONAL OS VERSION INFORMATION :
      all OS have problem

      A DESCRIPTION OF THE PROBLEM :
      In JDK1.5 Rotating graphics2D to draw chinese font string causes OutOfMemoryError,but in JDK1.4 everything is ok.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
      ACTUAL -
      Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import javax.swing.*;
      import java.util.Random;

      public class RotateString extends JFrame {
          private Font font = new Font("Dialog", Font.PLAIN, 12);
          Random random = new Random();

          public RotateString() {

              final JPanel canvas = new JPanel() {
                  public void paintComponent(Graphics g) {
                      super.paintComponent(g);
                      Graphics2D g2d = (Graphics2D) g;

                      int count = 1000;
                      int centerX = random.nextInt(300) + 150, centerY = random.nextInt(300 + 150);
                      for (int i = 0; i < count; i++) {
                          double angle = i * Math.PI * 2 / count;
                          g2d.translate(centerX, centerY);
                          g2d.rotate(angle);
                          g2d.setFont(font);
                          String text = " A B C D E F G ";
                          
                                          // In JDK1.5:
                          text += "<CJK GOES HERE>"; // if chinese is rotated, OutOfMemoryError is throwed.
                                          // but in JDK1.4 everything is ok.
                          
                          g2d.drawString(text, 100, 0);
                          g2d.drawLine(0, 0, 100, 0);
                          g2d.rotate( -angle);
                          g2d.translate( -centerX, -centerY);
                      }
                  }
              };

              Runnable r = new Runnable() {
                  public void run() {
                      while (true) {
                          canvas.repaint();
                          try {
                              Thread.sleep(500);
                          } catch (InterruptedException e) {
                              e.printStackTrace();
                          }
                      }
                  }
              };
              Thread t = new Thread(r);
              t.start();

              this.getContentPane().setLayout(new BorderLayout());
              this.getContentPane().add(new JScrollPane(canvas), BorderLayout.CENTER);
              this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
          }

          public static void main(String[] args) {
           RotateString test = new RotateString();
           test.setSize(600, 600);
              test.show();
          }

      }

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

      Release Regression From : 5.0
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

      Release Regression From : 5.0
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

            prr Philip Race
            prr Philip Race
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: