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

Bug 6253801 needs to be reopened.

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :

      A DESCRIPTION OF THE PROBLEM :
        Bug 6253801 needs to be reopened.
      ----------------------------------------------------
      The following function (updateLayoutState) in javax.swing.plaf.basic.BasicListUI class has a bug.
      On line number 19 getSize() method is being called on the List Model and an int array of this size (say OldSize) is contructed.
      On line number 32 getSize() method is called once again which returns a diffrent size (say NewSize) because new elements are added to the List Model.
      On line number 45 this array is accessed in range ( 0 to NewSize) but its size is OldSize. The loop should run (0 to array size) on line 36.

      This is a coding mistake and this bug should fixed.

      ---------- Class javax.swing.plaf.basic.BasicListUI ---------------
            1 protected void updateLayoutState()
            2 {
            3 /* If both JList fixedCellWidth and fixedCellHeight have been
            4 * set, then initialize cellWidth and cellHeight, and set
            5 * cellHeights to null.
            6 */
            7
            8 int fixedCellHeight = list.getFixedCellHeight();
            9 int fixedCellWidth = list.getFixedCellWidth();
           10
           11 cellWidth = (fixedCellWidth != -1) ? fixedCellWidth : -1;
           12
           13 if (fixedCellHeight != -1) {
           14 cellHeight = fixedCellHeight;
           15 cellHeights = null;
           16 }
           17 else {
           18 cellHeight = -1;
           19 cellHeights = new int[list.getModel().getSize()];
           20 }
           21
           22 /* If either of JList fixedCellWidth and fixedCellHeight haven't
           23 * been set, then initialize cellWidth and cellHeights by
           24 * scanning through the entire model. Note: if the renderer is
           25 * null, we just set cellWidth and cellHeights[*] to zero,
           26 * if they're not set already.
           27 */
           28
           29 if ((fixedCellWidth == -1) || (fixedCellHeight == -1)) {
           30
           31 ListModel dataModel = list.getModel();
           32 int dataModelSize = dataModel.getSize();
           33 ListCellRenderer renderer = list.getCellRenderer();
           34
           35 if (renderer != null) {
           36 for(int index = 0; index < dataModelSize; index++) {
           37 Object value = dataModel.getElementAt(index);
           38 Component c = renderer.getListCellRendererComponent(list, value, index, false, false);
           39 rendererPane.add(c);
           40 Dimension cellSize = c.getPreferredSize();
           41 if (fixedCellWidth == -1) {
           42 cellWidth = Math.max(cellSize.width, cellWidth);
           43 }
           44 if (fixedCellHeight == -1) {
           45 cellHeights[index] = cellSize.height;
           46 }
           47 }
           48 }
           49 else {
           50 if (cellWidth == -1) {
           51 cellWidth = 0;
           52 }
           53 if (cellHeights == null) {
           54 cellHeights = new int[dataModelSize];
           55 }
           56 for(int index = 0; index < dataModelSize; index++) {
           57 cellHeights[index] = 0;
           58 }
           59 }
           60 }
           61
           62 columnCount = 1;
           63 if (layoutOrientation != JList.VERTICAL) {
           64 updateHorizontalLayoutState(fixedCellWidth, fixedCellHeight);
           65 }
           66 }
           67

      REPRODUCIBILITY :
      This bug can be reproduced always.

        Attachments

          Activity

            People

            Assignee:
            shickeysunw Shannon Hickey (Inactive)
            Reporter:
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: