FULL PRODUCT VERSION :
java version "1.5.0_05"
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
undoInsert() in CachedRowSet cannot delete the first row.
assuming an empty CacheRowSet and inserting TWO new rows, doing:
crs.first();
crs.undoInsert();
removes the SECOND row. If more rows are inserted,
crs.absolute(2);
crs.undoInsert();
removes the THIRD row and so on.
The first row cannot be removed, since doing
crs.beforeFirst();
crs.undoInsert();
results in SQLException: Invalid cursor position.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
try
{
dataRowSet.beforeFirst();
dataRowSet.moveToInsertRow();
dataRowSet.updateXXX(...., .....)
..... // Make all the necessary updates
dataRowSet.insertRow();
dataRowSet.moveToCurrentRow();
dataRowSet.first();
dataRowSet.undoInsert();
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
crs.first();
crs.undoInsert();
Should remove the topmost (1st) row in a cached row set (assuming it is an inserted row) instead of removing the second one.
crs.absolute(2);
crs.undoInsert();
Should remove the 2nd row in a cached row set (assuming it is an inserted row) instead of removing the third one, and so on....
ACTUAL -
crs.first();
crs.undoInsert();
Removes the second row in a cached row set (or throws ArrayIndexOutOfBoundsException if the second row does not exist) instead of removing the 1st row.
crs.absolute(2);
crs.undoInsert();
Removes the third row in a cached row set (or throws ArrayIndexOutOfBoundsException if the thirdrow does not exist) instead of removing the 2nd row.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 1
at java.util.Vector.remove(Vector.java:791)
at com.sun.rowset.CachedRowSetImpl.undoInsert(CachedRowSetImpl.java:1026)
at TEST.CRSTest.removeButtonActionPerformed(CRSTest.java:72)
at TEST.CRSTest.access$100(CRSTest.java:8)
at TEST.CRSTest$2.actionPerformed(CRSTest.java:58)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1957)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2280)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:377)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:232)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5957)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3282)
at java.awt.Component.processEvent(Component.java:5722)
at java.awt.Container.processEvent(Container.java:1960)
at java.awt.Component.dispatchEventImpl(Component.java:4365)
at java.awt.Container.dispatchEventImpl(Container.java:2018)
at java.awt.Component.dispatchEvent(Component.java:4195)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4222)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3886)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3816)
at java.awt.Container.dispatchEventImpl(Container.java:2004)
at java.awt.Window.dispatchEventImpl(Window.java:2300)
at java.awt.Component.dispatchEvent(Component.java:4195)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package TEST;
import MAIN.CORE.ConnectionManager;
import com.sun.rowset.CachedRowSetImpl;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.rowset.CachedRowSet;
public class CRSTest extends javax.swing.JFrame
{
private ConnectionManager connectionManager = new ConnectionManager();
private Connection connection = // CONNECTION PROPERTIES
private CachedRowSet dataRowSet;
public CRSTest()
{
// This CachedRowSet is meant to be empty
// to better demonstrate the scenario, the
// SQL Select Statement should return no rows.
dataRowSet = new CachedRowSetImpl();
dataRowSet.setCommand("SELECT STRING");
dataRowSet.execute(connection);
initComponents();
try
{
dataRowSet.beforeFirst();
while (dataRowSet.next())
{
System.out.println("row: "+dataRowSet.getRow()+" religion_id: "+dataRowSet.getString("religion_id"));
}
System.out.println("");
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
}
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents()
{
addButton = new javax.swing.JButton();
removeButton = new javax.swing.JButton();
getContentPane().setLayout(new java.awt.GridLayout(2, 0));
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addButton.setText("Add to TOP");
addButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
addButtonActionPerformed(evt);
}
});
getContentPane().add(addButton);
removeButton.setText("Remove from TOP");
removeButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
removeButtonActionPerformed(evt);
}
});
getContentPane().add(removeButton);
pack();
}// </editor-fold>
private void removeButtonActionPerformed(java.awt.event.ActionEvent evt)
{
try
{
dataRowSet.beforeFirst();
dataRowSet.undoInsert();
dataRowSet.beforeFirst();
while (dataRowSet.next())
{
System.out.println("row: "+dataRowSet.getRow()+" religion_id: "+dataRowSet.getString("religion_id"));
}
System.out.println("");
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
}
private void addButtonActionPerformed(java.awt.event.ActionEvent evt)
{
try
{
dataRowSet.beforeFirst();
dataRowSet.moveToInsertRow();
dataRowSet.updateInt("religion_id", dataRowSet.size());
dataRowSet.updateString("description", "");
dataRowSet.insertRow();
dataRowSet.moveToCurrentRow();
dataRowSet.beforeFirst();
while (dataRowSet.next())
{
System.out.println("row: "+dataRowSet.getRow()+" religion_id: "+dataRowSet.getString("religion_id"));
}
System.out.println("");
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
}
public static void main(String args[])
{
new ConnectionManager().lookupConnections();
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new CRSTest().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton addButton;
private javax.swing.JButton removeButton;
// End of variables declaration
}
---------- END SOURCE ----------
java version "1.5.0_05"
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
undoInsert() in CachedRowSet cannot delete the first row.
assuming an empty CacheRowSet and inserting TWO new rows, doing:
crs.first();
crs.undoInsert();
removes the SECOND row. If more rows are inserted,
crs.absolute(2);
crs.undoInsert();
removes the THIRD row and so on.
The first row cannot be removed, since doing
crs.beforeFirst();
crs.undoInsert();
results in SQLException: Invalid cursor position.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
try
{
dataRowSet.beforeFirst();
dataRowSet.moveToInsertRow();
dataRowSet.updateXXX(...., .....)
..... // Make all the necessary updates
dataRowSet.insertRow();
dataRowSet.moveToCurrentRow();
dataRowSet.first();
dataRowSet.undoInsert();
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
crs.first();
crs.undoInsert();
Should remove the topmost (1st) row in a cached row set (assuming it is an inserted row) instead of removing the second one.
crs.absolute(2);
crs.undoInsert();
Should remove the 2nd row in a cached row set (assuming it is an inserted row) instead of removing the third one, and so on....
ACTUAL -
crs.first();
crs.undoInsert();
Removes the second row in a cached row set (or throws ArrayIndexOutOfBoundsException if the second row does not exist) instead of removing the 1st row.
crs.absolute(2);
crs.undoInsert();
Removes the third row in a cached row set (or throws ArrayIndexOutOfBoundsException if the thirdrow does not exist) instead of removing the 2nd row.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 1
at java.util.Vector.remove(Vector.java:791)
at com.sun.rowset.CachedRowSetImpl.undoInsert(CachedRowSetImpl.java:1026)
at TEST.CRSTest.removeButtonActionPerformed(CRSTest.java:72)
at TEST.CRSTest.access$100(CRSTest.java:8)
at TEST.CRSTest$2.actionPerformed(CRSTest.java:58)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1957)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2280)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:377)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:232)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5957)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3282)
at java.awt.Component.processEvent(Component.java:5722)
at java.awt.Container.processEvent(Container.java:1960)
at java.awt.Component.dispatchEventImpl(Component.java:4365)
at java.awt.Container.dispatchEventImpl(Container.java:2018)
at java.awt.Component.dispatchEvent(Component.java:4195)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4222)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3886)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3816)
at java.awt.Container.dispatchEventImpl(Container.java:2004)
at java.awt.Window.dispatchEventImpl(Window.java:2300)
at java.awt.Component.dispatchEvent(Component.java:4195)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package TEST;
import MAIN.CORE.ConnectionManager;
import com.sun.rowset.CachedRowSetImpl;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.rowset.CachedRowSet;
public class CRSTest extends javax.swing.JFrame
{
private ConnectionManager connectionManager = new ConnectionManager();
private Connection connection = // CONNECTION PROPERTIES
private CachedRowSet dataRowSet;
public CRSTest()
{
// This CachedRowSet is meant to be empty
// to better demonstrate the scenario, the
// SQL Select Statement should return no rows.
dataRowSet = new CachedRowSetImpl();
dataRowSet.setCommand("SELECT STRING");
dataRowSet.execute(connection);
initComponents();
try
{
dataRowSet.beforeFirst();
while (dataRowSet.next())
{
System.out.println("row: "+dataRowSet.getRow()+" religion_id: "+dataRowSet.getString("religion_id"));
}
System.out.println("");
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
}
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents()
{
addButton = new javax.swing.JButton();
removeButton = new javax.swing.JButton();
getContentPane().setLayout(new java.awt.GridLayout(2, 0));
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addButton.setText("Add to TOP");
addButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
addButtonActionPerformed(evt);
}
});
getContentPane().add(addButton);
removeButton.setText("Remove from TOP");
removeButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
removeButtonActionPerformed(evt);
}
});
getContentPane().add(removeButton);
pack();
}// </editor-fold>
private void removeButtonActionPerformed(java.awt.event.ActionEvent evt)
{
try
{
dataRowSet.beforeFirst();
dataRowSet.undoInsert();
dataRowSet.beforeFirst();
while (dataRowSet.next())
{
System.out.println("row: "+dataRowSet.getRow()+" religion_id: "+dataRowSet.getString("religion_id"));
}
System.out.println("");
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
}
private void addButtonActionPerformed(java.awt.event.ActionEvent evt)
{
try
{
dataRowSet.beforeFirst();
dataRowSet.moveToInsertRow();
dataRowSet.updateInt("religion_id", dataRowSet.size());
dataRowSet.updateString("description", "");
dataRowSet.insertRow();
dataRowSet.moveToCurrentRow();
dataRowSet.beforeFirst();
while (dataRowSet.next())
{
System.out.println("row: "+dataRowSet.getRow()+" religion_id: "+dataRowSet.getString("religion_id"));
}
System.out.println("");
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
}
public static void main(String args[])
{
new ConnectionManager().lookupConnections();
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new CRSTest().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton addButton;
private javax.swing.JButton removeButton;
// End of variables declaration
}
---------- END SOURCE ----------