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

Printables not initialising loop-counters within the print() don't print

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 9
    • 6u10
    • client-libs
    • 2d
    • x86
    • linux_ubuntu

      FULL PRODUCT VERSION :
      java version "1.6.0_18"
      Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
      Java HotSpot(TM) Server VM (build 16.0-b13, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux XXX 2.6.28.18 #1 SMP Sat Feb 20 21:26:20 CET 2010 i686 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      nothing special

      A DESCRIPTION OF THE PROBLEM :
      Implementations of Printable that do not initialize loop-counters within the
      print()-method give unexpected results, e.g. no printing is done.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      see source

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      two pages with 3 lines of text
      ACTUAL -
      one page with three lines of text, one empty page

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      no error message, no exceptions

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package de.notano.learning;

      import java.awt.*;
      import java.awt.print.*;

      /**
       * Implementations of Printable that does not init loop-counters within the
       * print()-method give unexpected results, e.g. no printing is done.
       *
       * EXAMPLE: Why this application prints one page like
       *
       * WorkingPrintable line 0
       * WorkingPrintable line 1
       * WorkingPrintable line 2
       *
       * and one EMPTY page, while it shows the following lines at System.err:
       *
       * printed line 0 failing?
       * printed line 1 failing?
       * printed line 2 failing?
       *
       *
       * used environment:
       *
       * jdk 1.6 rev 17
       * ubuntu 9.04
       * standard desktop pc
       *
       *
       *
       * any answers are welcome to ###@###.###.
       *
       * sincerely yours,
       *
       * Markus
       */
      public class PrintProblem {

      public static class WorkingPrintable implements Printable {

      private int loopCounter;
      @Override
      public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
      throws PrinterException {

      if(pageIndex>0) {
      return NO_SUCH_PAGE;
      }
      loopCounter = 0; // missing in FailingPrintable !!!
      Graphics2D g2d = (Graphics2D) graphics;
      g2d.translate(pageFormat.getImageableX(),pageFormat.getImageableY());

      for(;loopCounter<3;loopCounter++) {
      g2d.drawString(getClass().getSimpleName()+" line "+loopCounter,100,100+loopCounter*15);
      }

      return PAGE_EXISTS;
      }

      }


      public static class FailingPrintable implements Printable {

      private int loopCounter = 0; // done in method print() in WorkingPrintable

      @Override
      public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
      throws PrinterException {

      if(pageIndex>0) {
      return NO_SUCH_PAGE;
      }

      Graphics2D g2d = (Graphics2D) graphics;
      g2d.translate(pageFormat.getImageableX(),pageFormat.getImageableY());

      for(;loopCounter<3;loopCounter++) {
      g2d.drawString(getClass().getSimpleName()+" line "+loopCounter,100,100+loopCounter*15);
      System.err.println("printed line "+loopCounter+" failing?");
      }

      return PAGE_EXISTS;
      }
      }

      public static void test(String[] args) { // e.g. main
      try {
      PrinterJob workingJob = PrinterJob.getPrinterJob();
      workingJob.setPrintable(new WorkingPrintable());
      workingJob.print();

      PrinterJob failingJob = PrinterJob.getPrinterJob();
      failingJob.setPrintable(new FailingPrintable());
      failingJob.print();

      } catch(Exception ex) {
      ex.printStackTrace();
      }

      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      see class WorkingPrintable

            psadhukhan Prasanta Sadhukhan
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: