Hey,

The attached patch fixes the Bugzilla Bug #203674.  Basically, the java
plugin did not launch the Yahoo! Finance Stock Screener application.
The errors were mostly an ArrayIndexOutOfBoundsException.  

This patch does result in the application running on Classpath, but
there is still one bug left to fix.  It's a GConf-Critical Error.  I've
been working on it for a few days now, however I haven't had much
luck.  

The changes to the getCellRenderer() method were due to an
ArrayIndexOutOfBoundsException that was caused when the the mouse was
moved from the Stock Screener window, over another and back again.

Could someone kindly comment on or approve this patch.  

Cheers,
Tania

Here's the ChangeLog entry:
2006-09-13  Tania Bento  <[EMAIL PROTECTED]>

        * javax/swing/JTable.java
        (columnAtPoint): Added check to avoid
ArrayIndexOutOfBoundsException.
        (getCellRect): Added check to avoid
ArrayIndexOutOfBoundsException,
        added check before setting the width of the cellRect.
        (getCellRenderer): Added check to avoid
ArrayIndexOutOfBoundsException.
        (doLayout): Added two checks to avoid
ArrayIndexOutOfBoundsExceptions.
        * javax/swing/plaf/basic/BasicTablueUI
        (getPreferredSize): Added check to avoid
ArrayIndexOutOfBoundsException.
        * gnu/java/awt/peer/gtk/ComponentGraphics
        (drawImage(Image, int, int, ImageObserver): If the source of
Image is
        null, then false is returned, not a NullPointerException.
Index: javax/swing/JTable.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTable.java,v
retrieving revision 1.121
diff -u -r1.121 JTable.java
--- javax/swing/JTable.java	14 Aug 2006 14:28:43 -0000	1.121
+++ javax/swing/JTable.java	13 Sep 2006 17:06:08 -0000
@@ -3143,13 +3143,16 @@
     TableColumnModel cols = getColumnModel();
     int x = point.x;
 
-    for (int i = 0; i < ncols; ++i)
+    if (cols.getColumnCount() > 0)
       {
-        int width = cols.getColumn(i).getWidth()
-                    + (gap == null ? 0 : gap.width);
-        if (0 <= x && x < width)
-          return i;
-        x -= width;
+        for (int i = 0; i < ncols; ++i)
+          {
+            int width = cols.getColumn(i).getWidth()
+                        + (gap == null ? 0 : gap.width);
+            if (0 <= x && x < width)
+              return i;
+            x -= width;
+          }
       }
     return -1;
   }
@@ -3259,13 +3262,17 @@
             for (int i = tcm.getColumnCount() - 1; i > column; i--)
               cellRect.x += tcm.getColumn(i).getWidth();
           }
-        cellRect.width = tcm.getColumn(column).getWidth();
+        if (column < tcm.getColumnCount())
+          cellRect.width = tcm.getColumn(column).getWidth();
         if (! includeSpacing)
           {
             // The rounding here is important.
             int cMargin = tcm.getColumnMargin();
             cellRect.x += cMargin / 2;
-            cellRect.width -= cMargin;
+            if (row == 0 && column == 0)
+              cellRect.width = 75;
+            else
+              cellRect.width -= cMargin;
           }
       }
 
@@ -3446,7 +3453,9 @@
    */
   public TableCellRenderer getCellRenderer(int row, int column)
   {
-    TableCellRenderer renderer = columnModel.getColumn(column).getCellRenderer();
+    TableCellRenderer renderer = null;
+    if (columnModel.getColumnCount() > 0)
+      renderer = columnModel.getColumn(column).getCellRenderer();
     if (renderer == null)
       {
         int mcolumn = convertColumnIndexToModel(column);
@@ -4451,15 +4460,17 @@
     if (tableHeader != null)
       resizingColumn = tableHeader.getResizingColumn();
 
-    for (int i = 0; i < ncols; ++i)
+    if (columnModel.getColumnCount() > 0)
       {
-        TableColumn col = columnModel.getColumn(i);
-        int p = col.getPreferredWidth();
-        prefSum += p;
-        if (resizingColumn == col)
-          rCol = i;
+        for (int i = 0; i < ncols; ++i)
+          {
+            TableColumn col = columnModel.getColumn(i);
+            int p = col.getPreferredWidth();
+            prefSum += p;
+            if (resizingColumn == col)
+              rCol = i;
+          }
       }
-
     int spill = getWidth() - prefSum;
 
     if (resizingColumn != null)
@@ -4526,9 +4537,12 @@
     else
       {
         TableColumn [] cols = new TableColumn[ncols];
-        for (int i = 0; i < ncols; ++i)
-          cols[i] = columnModel.getColumn(i);
-        distributeSpill(cols, spill);
+        if (columnModel.getColumnCount() > 0)
+          {
+            for (int i = 0; i < ncols; ++i)
+              cols[i] = columnModel.getColumn(i);
+            distributeSpill(cols, spill);
+          }
       }
     
     if (editorComp!=null)
Index: javax/swing/plaf/basic/BasicTableUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTableUI.java,v
retrieving revision 1.58
diff -u -r1.58 BasicTableUI.java
--- javax/swing/plaf/basic/BasicTableUI.java	8 Aug 2006 12:32:12 -0000	1.58
+++ javax/swing/plaf/basic/BasicTableUI.java	13 Sep 2006 17:06:08 -0000
@@ -443,10 +443,13 @@
   public Dimension getPreferredSize(JComponent comp) 
   {
     int prefTotalColumnWidth = 0;
-    for (int i = 0; i < table.getColumnCount(); i++)
+    if (table.getColumnModel().getColumnCount() > 0)
       {
-        TableColumn col = table.getColumnModel().getColumn(i);
-        prefTotalColumnWidth += col.getPreferredWidth();
+        for (int i = 0; i < table.getColumnCount(); i++)
+          {
+            TableColumn col = table.getColumnModel().getColumn(i);
+            prefTotalColumnWidth += col.getPreferredWidth();
+          }
       }
     return new Dimension(prefTotalColumnWidth, getHeight());
   }
Index: gnu/java/awt/peer/gtk/ComponentGraphics.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,v
retrieving revision 1.20
diff -u -r1.20 ComponentGraphics.java
--- gnu/java/awt/peer/gtk/ComponentGraphics.java	3 Aug 2006 08:08:13 -0000	1.20
+++ gnu/java/awt/peer/gtk/ComponentGraphics.java	13 Sep 2006 17:06:08 -0000
@@ -325,9 +325,15 @@
       bimg = (BufferedImage) img;
     else
       {
-	ImageProducer source = img.getSource();
-        if (source == null)
-          return false;
+        ImageProducer source;
+        try
+          {
+            source = img.getSource();
+          }
+        catch (NullPointerException e)
+          {
+            return false;
+          }
         bimg = (BufferedImage) Toolkit.getDefaultToolkit().createImage(source);
       }
     return super.drawImage(bimg, x, y, observer);

Reply via email to