United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 7027139 getFirstIndex() does not return the first index that has changed
7027139 : getFirstIndex() does not return the first index that has changed

Details
Type:
Bug
Submit Date:
2011-03-13
Status:
Resolved
Updated Date:
2013-04-22
Project Name:
JDK
Resolved Date:
2012-03-27
Component:
client-libs
OS:
windows_xp
Sub-Component:
javax.swing
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
6u24
Fixed Versions:
8

Related Reports
Backport:

Sub Tasks

Description
FULL PRODUCT VERSION :
J2SEE 6

ADDITIONAL OS VERSION INFORMATION :
Windows XP

A DESCRIPTION OF THE PROBLEM :
An api that worked fine in JDK 1.4  is not working corrctly in 1.6:
The method getFirstIndex() on ListSelectionEvent. that has been working fine on JDK 1.4 is no longer working as expected in 1.6

The following code when executed  in 1.4 return the row whose selection status was changed.

        if (e.getSource() == orderTable.getSelectionModel() &&
            e.getFirstIndex() >= 0 && e.getValueIsAdjusting() == false)
        {
           .....
         .......
        }

In JDK i.6 if the event is triggered programatically likke by aTable.selectAll(),  e.getFirstIndex()  returns a -1 instead of the row that was selected.

REGRESSION.  Last worked in version 1.4.2

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Assign a  selection model to a jtable like
    ListSelectionModel selectionModel = orderTable.getSelectionModel();
    selectionModel.setSelectionMode(ListSelectionModel.
                                    MULTIPLE_INTERVAL_SELECTION);
//    jScrollPane1.getViewport().add(orderTable, null);
//        orderTable.setOpaque(false);
    selectionModel.addListSelectionListener(new ListSelectionListener()
    {
      public void valueChanged(ListSelectionEvent e)
      {
        if (e.getSource() == orderTable.getSelectionModel() &&
            e.getFirstIndex() >= 0 && e.getValueIsAdjusting() == false)
        {
          setOrderTableButtonState();
          setSkuForPendingOrderDataVector(
              convertSkuDetailForPendingAllocationOrderListToVector(
              getSkuDetailForSelectedSplitOrders()));

        }

      }
    });



and  ten programatically call selectAl() on the table.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
 e.getFirstIndex() returns0
ACTUAL -
 e.getFirstIndex() e.getFirstIndex() returns -1

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
                                    MULTIPLE_INTERVAL_SELECTION);
//    jScrollPane1.getViewport().add(orderTable, null);
//        orderTable.setOpaque(false);
    selectionModel.addListSelectionListener(new ListSelectionListener()
    {
      public void valueChanged(ListSelectionEvent e)
      {
        if (e.getSource() == orderTable.getSelectionModel() &&
            e.getFirstIndex() >= 0 && e.getValueIsAdjusting() == false)
        {
          setOrderTableButtonState();
          setSkuForPendingOrderDataVector(
              convertSkuDetailForPendingAllocationOrderListToVector(
              getSkuDetailForSelectedSplitOrders()));

        }

      }
    });


 orderTable.selectAll();

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

CUSTOMER SUBMITTED WORKAROUND :
Dont use  e.getFirstIndex() >= 0

                                    

Comments
EVALUATION

The problem exists from jdk 1.5. because the javax.swing.JTable#selectAll method was cardinally changed. The simplest fix is to deny set negative values to the firstAdjustedIndex and lastAdjustedIndex fields in the DefaultListSelectionModel#markAsDirty method. Those fields are used only for value changed notification (see fireValueChanged methods) and shouldn't be negative at all, because there are no rows with negative indexes.
                                     
2012-03-11
EVALUATION

regression case - so targeted to 7u6
                                     
2012-02-14
EVALUATION

A small regression from 1.4 to 1.6 is not treated as a P3, downgraded
                                     
2011-05-16



Hardware and Software, Engineered to Work Together