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

java.awt.Polygon.addPoint() array allocation buggy

    XMLWordPrintable

    Details

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

      Description

      Name: gm110360 Date: 09/09/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-rc-b63)
      Java HotSpot(TM) Client VM (build 1.5.0-rc-b63, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      xp sp1

      A DESCRIPTION OF THE PROBLEM :
      if the polygon has no points allocated, adding points to it fails because of lines 254 and 258. if npoints is 0 (i have the case), they allocate an empty array and then, writing in the array at line 262 fails. (writing at 0, in my case.)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      add the reteptools jar (pdf printing) to your lib/ext , so you can have the full example working.
      jar can be found at: http://retep.org/retep/pdf/home.do


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      no hanging . :)
      ACTUAL -
      hanging...

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      public class BrochureSample extends javax.swing.JPanel implements java.awt.print.Printable, javax.print.event.PrintJobListener
      {

      /** Creates new form BrochureSample */
      public BrochureSample()
      {
      initComponents();
      }

      /** This method is called from within the constructor to
      * initialize the form.
      * WARNING: Do NOT modify this code. The content of this method is
      * always regenerated by the Form Editor.
      */
        private void initComponents()
        {
          java.awt.GridBagConstraints gridBagConstraints;

          jLabel1 = new javax.swing.JLabel();
          jPanel1 = new javax.swing.JPanel();
          jPanel2 = new javax.swing.JPanel();
          jPanel3 = new javax.swing.JPanel();
          jPanel4 = new javax.swing.JPanel();
          jPanel5 = new javax.swing.JPanel();

          setLayout(new java.awt.GridBagLayout());

          setBackground(new java.awt.Color(0, 255, 0));
          setBorder(new javax.swing.border.TitledBorder("bla bla bla bla"));
          jLabel1.setBackground(new java.awt.Color(255, 51, 51));
          jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
          //jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/logo2.jpg")));
          jLabel1.setOpaque(true);
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 1;
          gridBagConstraints.gridy = 0;
          gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
          gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
          add(jLabel1, gridBagConstraints);

          jPanel1.setBackground(new java.awt.Color(255, 51, 255));
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 0;
          gridBagConstraints.gridy = 0;
          gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
          gridBagConstraints.weightx = 0.5;
          add(jPanel1, gridBagConstraints);

          jPanel2.setBackground(new java.awt.Color(255, 153, 153));
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 0;
          gridBagConstraints.gridy = 1;
          gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
          gridBagConstraints.weightx = 0.33;
          gridBagConstraints.weighty = 1.0;
          add(jPanel2, gridBagConstraints);

          jPanel3.setBackground(new java.awt.Color(204, 204, 0));
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 2;
          gridBagConstraints.gridy = 0;
          gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
          gridBagConstraints.weightx = 0.5;
          add(jPanel3, gridBagConstraints);

          jPanel4.setBackground(new java.awt.Color(204, 255, 204));
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 1;
          gridBagConstraints.gridy = 1;
          gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
          gridBagConstraints.weightx = 0.33;
          gridBagConstraints.weighty = 1.0;
          add(jPanel4, gridBagConstraints);

          jPanel5.setBackground(new java.awt.Color(102, 153, 255));
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 2;
          gridBagConstraints.gridy = 1;
          gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
          gridBagConstraints.weightx = 0.33;
          gridBagConstraints.weighty = 1.0;
          add(jPanel5, gridBagConstraints);

        }


        // Variables declaration - do not modify
        private javax.swing.JLabel jLabel1;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JPanel jPanel3;
        private javax.swing.JPanel jPanel4;
        private javax.swing.JPanel jPanel5;
        // End of variables declaration

      public static void main( String args[] )
      {
      // using JPS
      javax.print.PrintService services[] = javax.print.PrintServiceLookup.lookupPrintServices(null, null);
      javax.print.PrintService sve = null;
      for(int i=0;i<services.length;i++)
      {
      if(services[i].getName().startsWith("Retep PDF"))
      {
      sve = services[i];
      }
      }
      BrochureSample bro = new BrochureSample();

      javax.print.DocPrintJob dpj = sve.createPrintJob();
      javax.print.attribute.PrintRequestAttributeSet aset = new javax.print.attribute.HashPrintRequestAttributeSet( );
      aset.add( javax.print.attribute.standard.OrientationRequested.LANDSCAPE );
      // aset.add( new javax.print.attribute.standard.Copies(1) );
      // aset.add( new javax.print.attribute.standard.JobName( "Cyberproject", null ) );
      try
      {
      aset.add( new javax.print.attribute.standard.Destination(new java.net.URI("file:/c:/brojps.pdf")) );
      }
      catch ( Throwable t)
      {
      t.printStackTrace();
      }
      javax.print.Doc doc = new javax.print.SimpleDoc( bro, javax.print.DocFlavor.SERVICE_FORMATTED.PRINTABLE, null );
      try
      {
      dpj.addPrintJobListener( bro );
      dpj.print( doc, aset );
      System.out.println("imprim???");
      }
      catch( javax.print.PrintException e)
      {
      System.out.println("print exception");
      }
      System.exit( 0 );

      /*
      try
      {
      java.io.OutputStream fos = new java.io.FileOutputStream("c:\\bro.pdf");
      java.awt.PrintJob job = uk.org.retep.pdf.PDF.getPrintJob(fos);
      BrochureSample bro = new BrochureSample();
      // bro.paintAll( job.getGraphics() );
      job.getGraphics().drawString("Hello All how are u doing!!!", 250, 250);
      job.end();
      }
      catch ( Throwable t )
      {
       
      }
       */
      }

      public int print(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex) throws java.awt.print.PrinterException
      {
      int x = (int)pageFormat.getImageableX();
      int y = (int)pageFormat.getImageableY();
      graphics.translate(x, y);
      setSize( (int)pageFormat.getImageableWidth(), (int)pageFormat.getImageableHeight() );
      setPreferredSize( getSize() );
      validate();
      System.out.println("page index:"+pageIndex);
      if (pageIndex == 0)
      {
      System.out.println("printing");
      javax.swing.RepaintManager.currentManager( this ).setDoubleBufferingEnabled( false );
      paint(graphics);
      javax.swing.RepaintManager.currentManager( this ).setDoubleBufferingEnabled( true );
      return java.awt.print.Printable.PAGE_EXISTS;
      }
      else
      {
      return java.awt.print.Printable.NO_SUCH_PAGE;
      }

      }

      public void printDataTransferCompleted(javax.print.event.PrintJobEvent pje)
      {
      System.out.println("data transfer completed");
      }

      public void printJobCanceled(javax.print.event.PrintJobEvent pje)
      {
      System.out.println("cancelled");
      System.exit(0);
      }

      public void printJobCompleted(javax.print.event.PrintJobEvent pje)
      {
      System.out.println("completed");
      System.exit(0);
      }

      public void printJobFailed(javax.print.event.PrintJobEvent pje)
      {
      System.out.println("oops");
      System.exit(0);
      }

      public void printJobNoMoreEvents(javax.print.event.PrintJobEvent pje)
      {
      System.out.println("no more events");
      }

      public void printJobRequiresAttention(javax.print.event.PrintJobEvent pje)
      {
      System.out.println("watch out");
      }

      }


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class BrochureSample extends javax.swing.JPanel implements java.awt.print.Printable, javax.print.event.PrintJobListener
      {

      /** Creates new form BrochureSample */
      public BrochureSample()
      {
      initComponents();
      }

      /** This method is called from within the constructor to
      * initialize the form.
      * WARNING: Do NOT modify this code. The content of this method is
      * always regenerated by the Form Editor.
      */
        private void initComponents()
        {
          java.awt.GridBagConstraints gridBagConstraints;

          jLabel1 = new javax.swing.JLabel();
          jPanel1 = new javax.swing.JPanel();
          jPanel2 = new javax.swing.JPanel();
          jPanel3 = new javax.swing.JPanel();
          jPanel4 = new javax.swing.JPanel();
          jPanel5 = new javax.swing.JPanel();

          setLayout(new java.awt.GridBagLayout());

          setBackground(new java.awt.Color(0, 255, 0));
          setBorder(new javax.swing.border.TitledBorder("bla bla bla bla"));
          jLabel1.setBackground(new java.awt.Color(255, 51, 51));
          jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
          jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/logo2.jpg")));
          jLabel1.setOpaque(true);
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 1;
          gridBagConstraints.gridy = 0;
          gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
          gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
          add(jLabel1, gridBagConstraints);

          jPanel1.setBackground(new java.awt.Color(255, 51, 255));
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 0;
          gridBagConstraints.gridy = 0;
          gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
          gridBagConstraints.weightx = 0.5;
          add(jPanel1, gridBagConstraints);

          jPanel2.setBackground(new java.awt.Color(255, 153, 153));
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 0;
          gridBagConstraints.gridy = 1;
          gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
          gridBagConstraints.weightx = 0.33;
          gridBagConstraints.weighty = 1.0;
          add(jPanel2, gridBagConstraints);

          jPanel3.setBackground(new java.awt.Color(204, 204, 0));
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 2;
          gridBagConstraints.gridy = 0;
          gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
          gridBagConstraints.weightx = 0.5;
          add(jPanel3, gridBagConstraints);

          jPanel4.setBackground(new java.awt.Color(204, 255, 204));
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 1;
          gridBagConstraints.gridy = 1;
          gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
          gridBagConstraints.weightx = 0.33;
          gridBagConstraints.weighty = 1.0;
          add(jPanel4, gridBagConstraints);

          jPanel5.setBackground(new java.awt.Color(102, 153, 255));
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 2;
          gridBagConstraints.gridy = 1;
          gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
          gridBagConstraints.weightx = 0.33;
          gridBagConstraints.weighty = 1.0;
          add(jPanel5, gridBagConstraints);

        }


        // Variables declaration - do not modify
        private javax.swing.JLabel jLabel1;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JPanel jPanel3;
        private javax.swing.JPanel jPanel4;
        private javax.swing.JPanel jPanel5;
        // End of variables declaration

      public static void main( String args[] )
      {
      // using JPS
      javax.print.PrintService services[] = javax.print.PrintServiceLookup.lookupPrintServices(null, null);
      javax.print.PrintService sve = null;
      for(int i=0;i<services.length;i++)
      {
      if(services[i].getName().startsWith("Retep PDF"))
      {
      sve = services[i];
      }
      }
      BrochureSample bro = new BrochureSample();

      javax.print.DocPrintJob dpj = sve.createPrintJob();
      javax.print.attribute.PrintRequestAttributeSet aset = new javax.print.attribute.HashPrintRequestAttributeSet( );
      aset.add( javax.print.attribute.standard.OrientationRequested.LANDSCAPE );
      // aset.add( new javax.print.attribute.standard.Copies(1) );
      // aset.add( new javax.print.attribute.standard.JobName( "Cyberproject", null ) );
      try
      {
      aset.add( new javax.print.attribute.standard.Destination(new java.net.URI("file:/c:/brojps.pdf")) );
      }
      catch ( Throwable t)
      {
      t.printStackTrace();
      }
      javax.print.Doc doc = new javax.print.SimpleDoc( bro, javax.print.DocFlavor.SERVICE_FORMATTED.PRINTABLE, null );
      try
      {
      dpj.addPrintJobListener( bro );
      dpj.print( doc, aset );
      System.out.println("imprim???");
      }
      catch( javax.print.PrintException e)
      {
      System.out.println("print exception");
      }
      System.exit( 0 );

      /*
      try
      {
      java.io.OutputStream fos = new java.io.FileOutputStream("c:\\bro.pdf");
      java.awt.PrintJob job = uk.org.retep.pdf.PDF.getPrintJob(fos);
      BrochureSample bro = new BrochureSample();
      // bro.paintAll( job.getGraphics() );
      job.getGraphics().drawString("Hello All how are u doing!!!", 250, 250);
      job.end();
      }
      catch ( Throwable t )
      {
       
      }
       */
      }

      public int print(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex) throws java.awt.print.PrinterException
      {
      int x = (int)pageFormat.getImageableX();
      int y = (int)pageFormat.getImageableY();
      graphics.translate(x, y);
      setSize( (int)pageFormat.getImageableWidth(), (int)pageFormat.getImageableHeight() );
      setPreferredSize( getSize() );
      validate();
      System.out.println("page index:"+pageIndex);
      if (pageIndex == 0)
      {
      System.out.println("printing");
      javax.swing.RepaintManager.currentManager( this ).setDoubleBufferingEnabled( false );
      paint(graphics);
      javax.swing.RepaintManager.currentManager( this ).setDoubleBufferingEnabled( true );
      return java.awt.print.Printable.PAGE_EXISTS;
      }
      else
      {
      return java.awt.print.Printable.NO_SUCH_PAGE;
      }

      }

      public void printDataTransferCompleted(javax.print.event.PrintJobEvent pje)
      {
      System.out.println("data transfer completed");
      }

      public void printJobCanceled(javax.print.event.PrintJobEvent pje)
      {
      System.out.println("cancelled");
      System.exit(0);
      }

      public void printJobCompleted(javax.print.event.PrintJobEvent pje)
      {
      System.out.println("completed");
      System.exit(0);
      }

      public void printJobFailed(javax.print.event.PrintJobEvent pje)
      {
      System.out.println("oops");
      System.exit(0);
      }

      public void printJobNoMoreEvents(javax.print.event.PrintJobEvent pje)
      {
      System.out.println("no more events");
      }

      public void printJobRequiresAttention(javax.print.event.PrintJobEvent pje)
      {
      System.out.println("watch out");
      }

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      none.
      correction would be to handle the case where npoints is 0 and set it to ... 1 before doing the multiplications for array allocation...
      (Incident Review ID: 302157)
      ======================================================================</TEXTAREA>
      </td>
                          </tr>
                          <TR>
                            <TD colspan="2" bgcolor="#BFBFBF"> </td>
                          </tr>
      ###@###.### 10/25/04 23:26 GMT
      <a name="comments"></a>
                          <!-- COMMENTS -->
                          <TR>
                            <TD bgcolor="#BFBFBF" align="left" valign="bottom" height="24">
      <img src="https://central.sun.net/https%3A//swbtres.central.sun.com%3A443/bugz/images/dot.gif" width="10">Comments
      </td>
                            <TD bgcolor="#BFBFBF" align="left" valign="bottom" height="24">
      <!-- BEGIN:TBR Mohan
        <A href="javascript:doDateStampSubmit(document.editbug_general, 'comments');"><font size="-1">[ Date Stamp ]</font></A>
      <img src="https://central.sun.net/https%3A//swbtres.central.sun.com%3A443/bugz/images/dot.gif" width="18">
      END:TBR -->
      <A href="javascript:doFullPageSubmit(document.editbug_general, 'comments');"><font size="-1">[ Full Page ]</font></a>
      <img src="https://central.sun.net/https%3A//swbtres.central.sun.com%3A443/bugz/images/dot.gif" width="22">
      <FONT size="-1" color="darkblue">--- Enter SUN Proprietary data here ---</font>
      </td>
                          </tr>

                          <TR>
                            <TD bgcolor="#BFBFBF" colspan="2" nowrap align="left">
      <img src="https://central.sun.net/https%3A//swbtres.central.sun.com%3A443/bugz/images/dot.gif" width="5">
                              <TEXTAREA rows="6" cols="95" wrap="virtual" name="comments" align="left" bgcolor="white">

      Name: gm110360 Date: 09/09/2004


      (company - i/o labs , email - ###@###.###)
      ======================================================================
      ###@###.### 2004-09-10
      ###@###.### 2004-09-14

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              avu Alexey Ushakov
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: