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

StackOverflowError printing landscape with scale and transform.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 6u13
    • Fix Version/s: 9
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
      2d
    • Resolved In Build:
      b124
    • CPU:
      x86
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_13"
      Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
      Java HotSpot(TM) Server VM (build 11.3-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux granite 2.6.28-11-generic #42-Ubuntu SMP Fri Apr 17 01:57:59 UTC 2009 i686 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      I have verified the problem on both 32-bit and 64-bit environments.

      A DESCRIPTION OF THE PROBLEM :
      A StackOverflowError occurs when printing in landscape orientation with a scaled and transformed graphics object. The error does not occur when printing in portrait orientation.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :

      Exception in thread "main" java.lang.StackOverflowError
          at sun.nio.cs.UTF_8.updatePositions(UTF_8.java:58)
          at sun.nio.cs.UTF_8$Encoder.encodeArrayLoop(UTF_8.java:392)
          at sun.nio.cs.UTF_8$Encoder.encodeLoop(UTF_8.java:447)
          at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:544)
          at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:252)
          at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:106)
          at java.io.OutputStreamWriter.write(OutputStreamWriter.java:190)
          at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:111)
          at java.io.PrintStream.write(PrintStream.java:476)
          at java.io.PrintStream.print(PrintStream.java:619)
          at java.io.PrintStream.println(PrintStream.java:756)
          at sun.print.PSPrinterJob.grestore(PSPrinterJob.java:1670)
          at sun.print.PSPrinterJob.prepDrawing(PSPrinterJob.java:1610)
          at sun.print.PSPrinterJob.beginPath(PSPrinterJob.java:1319)
          at sun.print.PSPrinterJob.convertToPSPath(PSPrinterJob.java:1793)
          at sun.print.PSPrinterJob$GState.emitPSClip(PSPrinterJob.java:1718)
          at sun.print.PSPrinterJob.prepDrawing(PSPrinterJob.java:1625)
          at sun.print.PSPrinterJob.beginPath(PSPrinterJob.java:1319)
          at sun.print.PSPrinterJob.convertToPSPath(PSPrinterJob.java:1793)
          at sun.print.PSPrinterJob$GState.emitPSClip(PSPrinterJob.java:1718)
          at sun.print.PSPrinterJob.prepDrawing(PSPrinterJob.java:1625)
          at sun.print.PSPrinterJob.beginPath(PSPrinterJob.java:1319)
          at sun.print.PSPrinterJob.convertToPSPath(PSPrinterJob.java:1793)
          at sun.print.PSPrinterJob$GState.emitPSClip(PSPrinterJob.java:1718)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.geom.Path2D;
      import java.awt.print.PageFormat;
      import java.awt.print.Printable;
      import java.awt.print.PrinterException;
      import java.awt.print.PrinterJob;

      import javax.print.PrintService;
      import javax.print.attribute.HashPrintRequestAttributeSet;
      import javax.print.attribute.PrintRequestAttributeSet;
      import javax.print.attribute.standard.OrientationRequested;

      public class LandscapeStackOverflow {

      public static final void main( String[] parameters ) {
      PrinterJob printjob = PrinterJob.getPrinterJob();
      printjob.setJobName( "Test Print Job" );

      PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
      attributes.add( OrientationRequested.LANDSCAPE );

      boolean print = printjob.printDialog( attributes );
      if( !print ) return;

      try {
      printjob.setPrintable( new Painter() );
      printjob.print( attributes );
      } catch( PrinterException exception ) {
      exception.printStackTrace();
      }
      }

      }

      /**
       * Paints a 2 inch by 2 inch rectangle in the center of the page.
       */
      class Painter implements Printable {

      public int print( Graphics graphics, PageFormat format, int index ) {
      Graphics2D g2d = (Graphics2D)graphics;

      double scalex = g2d.getTransform().getScaleX();
      double scaley = g2d.getTransform().getScaleY();

      double centerx = ( format.getImageableX() + ( format.getImageableWidth() / 2 ) ) * scalex;
      double centery = ( format.getImageableY() + ( format.getImageableHeight() / 2 ) ) * scaley;

      // The following to lines cause an error when printing in landscape.
      g2d.scale( 1 / scalex, 1 / scaley );
      g2d.translate( centerx, centery );

      Path2D.Double path = new Path2D.Double();
      path.moveTo( -scalex * 72, -scaley * 72 );
      path.lineTo( -scalex * 72, scaley * 72 );
      path.lineTo( scalex * 72, scaley * 72 );
      path.lineTo( scalex * 72, -scaley * 72 );
      path.closePath();

      g2d.draw( path );

      return index == 0 ? PAGE_EXISTS : NO_SUCH_PAGE;
      }

      }

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              psadhukhan Prasanta Sadhukhan
              Reporter:
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: