United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6428395 Potential problem with handling read() javax.sql.rowset.serial.SerialClob.position(...)
JDK-6428395 : Potential problem with handling read() javax.sql.rowset.serial.SerialClob.position(...)

Details
Type:
Bug
Submit Date:
2006-05-20
Status:
Resolved
Updated Date:
2014-02-27
Project Name:
JDK
Resolved Date:
2007-07-11
Component:
core-libs
OS:
generic
Sub-Component:
javax.sql
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:
6u4 (b01)

Related Reports

Sub Tasks

Description
Current implementation of
javax.sql.rowset.serial.SerialClob.position(Clob searchStr, long start)
has following code:

   311      public long position(Clob searchStr, long start)
   312          throws SerialException, SQLException {
   313
   314          char cPattern[] = null;
   315          try {
   316              java.io.Reader r = searchStr.getCharacterStream();
   317              cPattern = new char[(int)searchStr.length()];
   318              r.read(cPattern);
   319          } catch (IOException e) {
   320              throw new SerialException("Error streaming Clob search data");
   321          }
   322          return position(new String(cPattern), start);
   323      }

However, Reader.read(byte[] b) doesn't guarantee that exactly b.length
bytes will be read. So, the code has potential problems in case less than b.length
bytes are returned. While this is probably hardly reproducible in real
apps theoretically it might happen - so it seems better to update code to protect from this.
E.g.

    int totalRead = 0;
    while ( totalRead < cPattern.length() )
    {
        totalRead += r.read(cPattern, totalRead, cPattern.length - totalRead);
    }


Btw, why just don't use searchStr.getSubString(0, searchStr.length)
instead of reading from the streams?
Looks like from performance point of view it is better to use getSubString.

                                    

Comments
EVALUATION

Deferring it to next release of jdk
                                     
2006-07-20



Hardware and Software, Engineered to Work Together