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

javax.sql.rowset.serial.SerialClob throws unexpected NPE

XMLWordPrintable

    • b58
    • sparc
    • solaris_2.6



        Name: sdR10048 Date: 06/15/2004


        Filed By : SPB JCK team (###@###.###)
        JDK : build 1.5.0-beta3-b55
        JCK : 1.5
        JCK test owner : http://javaweb.eng/jct/sqe/JCK-tck/usr/owners.jto
        Failing Test [s] :
        api/javax_sql/rowset/BaseRowSet/index.html#Params2[BaseRowSet0025]
        (the new, updated version of this testcase will be in WS soon.
         Meanwhile please refer to mini demo J.java)

        Specification excerpt:
        ======================
        --------- J2SE API spec v.1.5 ---------
        ...
        public SerialClob(Clob clob)
                   throws SerialException,
                          SQLException
        Constructs a SerialClob object that is a serialized version of the given Clob object.

        The new SerialClob object is initialized with the data from the Clob object; therefore, the Clob object should have previously brought the SQL CLOB value's data over to the client from the database. Otherwise, the new SerialClob object object will contain no data.

        Note: The Clob object supplied to this constructor cannot return null for the Clob.getCharacterStream() and Clob.getAsciiStream methods. This SerialClob constructor cannot serialize a Clob object in this instance and will throw an SQLException object.

        Parameters:
        clob - the Clob object from which this SerialClob object is to be constructed; cannot be null
        Throws:
        SerialException - if an error occurs during serialization
        SQLException - if a SQL error occurs in capturing the CLOB; if the Clob object is a null; or if both the Clob.getCharacterStream() and Clob.getAsciiStream() methods on the Clob return a null
        ...
        ---------- end-of-excerpt ---------------

        Problem description
        ===================
        The designated method throws NPE if one of clob.getCharacterStream() and clob.getAsciiStream() returns null. The spec says that "botht he Clob.getCharacterStream()
        and Clob.getAsciiStream() methods on the Clob" should return null to see SQLException.
        (Note: SQLException but not NullPointerException)


            
        Minimized test:
        ===============
        ------- J.java -------
        import javax.sql.rowset.serial.*;
        import java.io.*;
        import java.sql.*;


        class MyClob implements Clob {
            public long length()
                throws SQLException {
                return 3;
            }
            public String getSubString(long pos, int length)
                throws SQLException {
                return "abd";
            }
            public Reader getCharacterStream()
                throws SQLException {
                return null;
            }
            public InputStream getAsciiStream()
                throws SQLException {
                return new ByteArrayInputStream(new byte[] {'a', 'b', 'c'});
            }
            public long position(String searchstr,
                                 long start)
                throws SQLException {
                return 0;
            }
            public long position(Clob searchstr,
                                 long start)
                throws SQLException {
                return 0;
            }
            public int setString(long pos,
                                 String str)
                throws SQLException {
                return 0;
            }
            public int setString(long pos,
                                 String str,
                                 int offset,
                                 int len)
                throws SQLException {
                return 0;
            }
            public OutputStream setAsciiStream(long pos)
                throws SQLException {
                return null;
            }
            public Writer setCharacterStream(long pos)
                throws SQLException {
                return null;
            }
            public void truncate(long len)
                throws SQLException {
            }
        }

        public class J {
            public static void main(String args[]) {
                try {
                    MyClob myClob = new MyClob();
                    SerialClob sClob = new SerialClob(myClob);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        ------- end-of-J.java -------

        Minimized test output:
        ======================
        ] java -showversion J
        java version "1.5.0-beta3"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b55)
        Java HotSpot(TM) Client VM (build 1.5.0-beta3-b55, mixed mode)

        java.lang.NullPointerException
                at java.io.Reader.<init>(Reader.java:61)
                at java.io.BufferedReader.<init>(BufferedReader.java:76)
                at java.io.BufferedReader.<init>(BufferedReader.java:91)
                at javax.sql.rowset.serial.SerialClob.<init>(SerialClob.java:130)
                at J.main(J.java:62)


        ======================================================================

              ahandasunw Amit Handa (Inactive)
              dsvsunw Dsv Dsv (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: