JDK-7166598 : FilteredRowSetImpl can result in Invalid Cursor Position
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.sql
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2012-05-04
  • Updated: 2012-05-22
  • Resolved: 2012-05-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b40Fixed
Description
FilteredRowsetImpl will return the following error:

 [java] java.sql.SQLException: Invalid cursor position
   [java] 	at com.sun.rowset.CachedRowSetImpl.checkCursor(CachedRowSetImpl.java:1612)
   [java] 	at com.sun.rowset.CachedRowSetImpl.getInt(CachedRowSetImpl.java:1875)
   [java] 	at com.oracle.tutorial.jdbc.StateFilter.evaluate(StateFilter.java:96)
   [java] 	at com.sun.rowset.FilteredRowSetImpl.internalNext(FilteredRowSetImpl.java:133)
   [java] 	at com.sun.rowset.CachedRowSetImpl.next(CachedRowSetImpl.java:1465)
   [java] 	at com.oracle.tutorial.jdbc.FilteredRowSetSample.viewFilteredRowSet(FilteredRowSetSample.java:71)
   [java] 	at com.oracle.tutorial.jdbc.FilteredRowSetSample.testFilteredRowSet(FilteredRowSetSample.java:128)
   [java] 	at com.oracle.tutorial.jdbc.FilteredRowSetSample.main(FilteredRowSetSample.java:162)

Comments
EVALUATION Fix was provided by Knut Anders Hatlen: I see the same stack trace when running FilteredRowSetSample against MySQL. It looks to me as if there's a bug in FilteredRowSetImpl.internalNext(). http://opengrok.ie.oracle.com:8080/opengrok/xref/jdk7u-dev/jdk/src/share/classes/com/sun/rowset/FilteredRowSetImpl.java#internalNext If super.internalNext() returns false to indicate that the position is after the last row, and there is a filter installed, p.evaluate(this) will be called on a RowSet that is not on a valid position. So it would seem that a filter would always fail this way when it goes past the last row. The reason why it hasn't been detected before, is probably that Predicate.evaluate(RowSet) is not declared to throw any kind of exception, so implementations typically just catch SQLException and silently return false to satisfy the interface. The StateFilter class in the tutorial, on the other hand, prints the SQLException's stack trace before it returns false, and thereby exposes the bug. When I applied the patch in the attachment, which makes FilteredRowSetImpl.internalNext() return without evaluating the predicate if it's positioned after the last row, the sample runs successfully. Both with Java DB and MySQL. ----- Reviewed fix and it makes sense and ran the RowSet 1.1 TCK to validate that there are no issues after applying the fix
04-05-2012