JDK-6984864 : Exception when running acceptChanges with custom SyncProvider
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.sql
  • Affected Version: 7
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2010-09-15
  • Updated: 2012-03-22
  • Resolved: 2010-10-13
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 7
7 b114Fixed
Related Reports
Relates :  
Description
It turned out that an exception occurs when a write data action is being delegated to a custom rowset SyncProvider for any of the Cashed rowset implementations.

Here a minimized test that demonstrates the problem.

---------------- Test.java -----------------------
import java.io.Serializable;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.sql.Types;
import javax.sql.rowset.spi.*;
import javax.sql.rowset.*;
import javax.sql.*;

public class Test extends SyncProvider implements RowSetReader,
        TransactionalWriter, Cloneable, Serializable, RowSetListener {

    static {
        try {            
            SyncFactory.registerProvider(Test.class.getName());
        } catch (SyncFactoryException ex) {
            throw new RuntimeException(ex);
        }
    }
    protected int datasource_lock = SyncProvider.DATASOURCE_NO_LOCK;

    public void setDataSourceLock(int datasource_lock)
            throws SyncProviderException {
        this.datasource_lock = datasource_lock;
    }

    public int supportsUpdatableView() {
        return SyncProvider.UPDATABLE_VIEW_SYNC;
    }

    public String getVersion() {
        return "1.0";
    }

    public String getVendor() {
        return "Spb JCK Team";
    }

    public RowSetWriter getRowSetWriter() {
        return this;
    }

    public RowSetReader getRowSetReader() {
        return this;
    }

    public String getProviderID() {
        return getClass().getName();
    }

    public int getProviderGrade() {
        return SyncProvider.GRADE_NONE;
    }

    public int getDataSourceLock() throws SyncProviderException {
        return datasource_lock;
    }

    public boolean writeData(RowSetInternal caller) throws
            java.sql.SQLException {
        System.out.println("writeData");
        return true;
    }

    public void readData(RowSetInternal caller) throws java.sql.SQLException {
        System.out.println("readData");
    }

    public void rowSetChanged(RowSetEvent event) {
        System.out.println("rowSetChanged");
    }

    public void rowChanged(RowSetEvent event) {
        System.out.println("rowChanged");
    }

    public void cursorMoved(RowSetEvent event) {
        System.out.println("cursorMoved");
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public static void main(String[] argv) throws Exception {
        final CachedRowSet crs = new com.sun.rowset.CachedRowSetImpl();
        
        crs.setSyncProvider(Test.class.getName());
        crs.setType(RowSet.TYPE_SCROLL_INSENSITIVE);
        RowSetMetaDataImpl rsmdi = new RowSetMetaDataImpl();
        rsmdi.setColumnCount(1);
        rsmdi.setColumnName(1, "_char_");
        rsmdi.setColumnType(1, Types.CHAR);
        crs.setMetaData(rsmdi);
        crs.moveToInsertRow();
        crs.updateString(1, "Char value");
        crs.insertRow();
        crs.moveToCurrentRow();

        System.out.println("READY");
        crs.acceptChanges();
        System.out.println("DONE");
    }

    public void commit() throws SQLException {

    }

    public void rollback() throws SQLException {

    }

    public void rollback(Savepoint s) throws SQLException {
        
    }

}
---------------------------------------------------

<ag153348@spb-piker> java7 -showversion -cp /net/spb-piker/export/users/ag153348/trash/JavaApplication5/build/classes Test
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b109)
Java HotSpot(TM) Server VM (build 19.0-b06, mixed mode)

READY
writeData
Exception in thread "main" java.lang.ClassCastException: Test cannot be cast to com.sun.rowset.internal.CachedRowSetWriter
	at com.sun.rowset.CachedRowSetImpl.acceptChanges(CachedRowSetImpl.java:889)
	at Test.main(Test.java:101)


It looks like this program fails due to incorrect type casting of the RowSetWriter instance to the internal type.

Comments
EVALUATION Provided a fix to the JCK team to try. The RI never supported this functionality
15-09-2010