Issue Details (XML | Word | Printable)

Key: DERBY-721
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Tomohito Nakayama
Reporter: Tomohito Nakayama
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Derby

State of InputStream retrieved from resultset is not clean , if there exists previous InputStream .

Created: 21/Nov/05 08:23 PM   Updated: 30/Jun/09 04:12 PM
Return to search
Component/s: JDBC, Network Client
Affects Version/s: None
Fix Version/s: 10.2.1.6

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works DERBY-721.patch 2005-11-24 11:24 PM Tomohito Nakayama 6 kB
Text File Licensed for inclusion in ASF works DERBY-721_2.patch 2005-11-29 12:59 AM Tomohito Nakayama 6 kB
Text File Licensed for inclusion in ASF works DERBY-721_3.patch 2005-12-03 03:12 PM Tomohito Nakayama 5 kB
Text File Licensed for inclusion in ASF works DERBY-721_4.patch 2005-12-16 12:05 AM Tomohito Nakayama 180 kB
Text File Licensed for inclusion in ASF works DERBY-721_5.patch 2005-12-19 11:59 PM Tomohito Nakayama 0.9 kB
Text File Licensed for inclusion in ASF works DERBY-721_rollback_1+2.patch 2005-12-08 10:36 PM Tomohito Nakayama 10 kB
Java Source File Licensed for inclusion in ASF works testLob.java 2005-11-21 08:26 PM Tomohito Nakayama 2 kB
Java Source File Licensed for inclusion in ASF works testLob2.java 2005-11-28 08:53 PM Tomohito Nakayama 2 kB
Text File Licensed for inclusion in ASF works testResult.txt 2005-11-21 08:26 PM Tomohito Nakayama 0.1 kB
Text File Licensed for inclusion in ASF works testResult2.txt 2005-11-28 08:53 PM Tomohito Nakayama 0.1 kB
Environment:
naka@rufelza:~/derby/dev/trunk$ cat /proc/version
Linux version 2.6.12-1-386 (horms@tabatha.lab.ultramonkey.org) (gcc version 4.0.2 20050917 (prerelease) (Debian 4.0.1-8)) #1 Tue Sep 27 12:41:08 JST 2005
naka@rufelza:~/derby/dev/trunk$ java -version
java version "1.4.2_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_10-b03)
Java HotSpot(TM) Client VM (build 1.4.2_10-b03, mixed mode)
Issue Links:
Blocker
 
Reference
 

Issue & fix info: Release Note Needed
Resolution Date: 20/Dec/05 09:10 PM


 Description  « Hide
State of InputStream retrieved from ResultSet was not clean , if there exists previous InputStream retrieved from ResultSet .

Test code ...
PreparedStatement pst = conn.prepareStatement("insert into a(b) values(?)");

byte[] data = new byte[1024 * 1024];
for(int i = 0;
i < 1024 * 1024;
i ++){
data[i] = (byte)(i % 256);
}

pst.setBinaryStream(1,new ByteArrayInputStream(data),data.length);
pst.executeUpdate();
pst.close();


st = conn.createStatement();
ResultSet rs = st.executeQuery("select b from a");
rs.next();

InputStream is = rs.getBinaryStream(1);
System.out.println("Here goes first stream");
System.out.println(is.read());
System.out.println(is.read());
System.out.println(is.read());

is = rs.getBinaryStream(1);
System.out.println("Here goes 2nd stream");
System.out.println(is.read());
System.out.println(is.read());
System.out.println(is.read());

Result ....
naka@rufelza:~/derby/test/20051121$ java testLob
Here goes first stream
0
1
2
Here goes 2nd stream
7
8
9

It is expected that result printed from first stream is as same as result printed from 2nd.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Tomohito Nakayama added a comment - 21/Nov/05 08:26 PM
These are test program for reproduction of the phenomena what I found , and result of the program .

Tomohito Nakayama made changes - 21/Nov/05 08:26 PM
Field Original Value New Value
Attachment testLob.java [ 12320823 ]
Attachment testResult.txt [ 12320824 ]
Tomohito Nakayama made changes - 23/Nov/05 02:59 PM
Link This issue blocks DERBY-326 [ DERBY-326 ]
Tomohito Nakayama added a comment - 23/Nov/05 03:07 PM
I found that this phenomena does not happen if data length was small, such as 32.

Class of inputstream was different between when phenomena happen and when does not.

When phenomena happens:
main[1] eval is
 is = "org.apache.derby.impl.jdbc.BinaryToRawStream@29d294"

When phenomena does not happen.
main[1] eval is
 is = "org.apache.derby.iapi.services.io.NewByteArrayInputStream@19abd2b"

I suspect closing process of BinaryToRawStream ...

Tomohito Nakayama made changes - 23/Nov/05 03:45 PM
Assignee Tomohito Nakayama [ naka ]
Tomohito Nakayama added a comment - 23/Nov/05 04:05 PM
I found that BinaryToRawStream is subclass of java.io.FilteredInputStream and
would just close source InputStream when close method was called.

However, source InputStream was shared between bunch of destination InputStream.
Then, just closing source InputStream may be not correct.

I found when this phenomena was found , substantial class of source InputStream object implements Resetable .

I will call method to reset source InputStream object ,if it was Resetable object , in BinaryToRawSteream.

Tomohito Nakayama added a comment - 24/Nov/05 11:24 PM
Description of the patch:
  Modified close method of org.apache.derby.impl.jdbc.BinaryToRawStream to reset source InputStream which implements Resetable interface,
  because the source InputStream is shared with following InputStream.

Test:
 execute derbyall and found no error.

Tomohito Nakayama made changes - 24/Nov/05 11:24 PM
Attachment DERBY-721.patch [ 12320938 ]
Repository Revision Date User Message
ASF #349079 Sat Nov 26 05:14:15 UTC 2005 tmnk - DERBY-721 State of InputStream retrieved from resultset is not clean , if there exists previous InputStream - Patch by Tomohito Nakayama (tomonaka@basil.ocn.ne.jp)
Files Changed
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/BinaryToRawStream.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java

Tomohito Nakayama added a comment - 26/Nov/05 02:16 PM
Committed

Sending java/engine/org/apache/derby/impl/jdbc/BinaryToRawStream.java
Sending java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out
Sending java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
Sending java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java
Transmitting file data ....
Committed revision 349079.

Tomohito Nakayama made changes - 26/Nov/05 02:19 PM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Tomohito Nakayama added a comment - 28/Nov/05 08:52 PM
I found same problem in getCharacterStream ...

Tomohito Nakayama made changes - 28/Nov/05 08:52 PM
Resolution Fixed [ 1 ]
Status Resolved [ 5 ] Reopened [ 4 ]
Tomohito Nakayama added a comment - 28/Nov/05 08:53 PM
These are test to reproduce phenomena found at getCharacterStream

Tomohito Nakayama made changes - 28/Nov/05 08:53 PM
Attachment testLob2.java [ 12321000 ]
Attachment testResult2.txt [ 12321001 ]
Tomohito Nakayama made changes - 28/Nov/05 11:13 PM
Status Reopened [ 4 ] In Progress [ 3 ]
Tomohito Nakayama added a comment - 29/Nov/05 12:59 AM
Patch for the phenomena found in getCharacterStream

Description:
   Modified to reset the source InputStream instead of closing it , when org.apache.derby.impl.jdbc.UTF8Reader was closed.

Test:
   Executed derbyall and does not found new error other than found in http://www.multinet.no/~solberg/public/Apache/Derby/Limited/index.html already.

Tomohito Nakayama made changes - 29/Nov/05 12:59 AM
Attachment DERBY-721_2.patch [ 12321008 ]
Repository Revision Date User Message
ASF #349718 Tue Nov 29 14:02:22 UTC 2005 tmnk - DERBY-721_2 State of Reader retrieved from resultset is not clean , if there exists previous Reader - Patch by Tomohito Nakayama (tomonaka@basil.ocn.ne.jp)
Files Changed
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java

Tomohito Nakayama added a comment - 29/Nov/05 11:04 PM
patch commited.


Sending java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
Sending java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java
Sending java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out
Sending java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
Sending java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java
Transmitting file data .....
Committed revision 349718.

Tomohito Nakayama made changes - 29/Nov/05 11:04 PM
Status In Progress [ 3 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Tomohito Nakayama added a comment - 29/Nov/05 11:29 PM
Dan wrote:

The error handling is incorrect here, and I think in at least one other
place in the patch.

1) Derby should not be printing stack traces to System.err, it should
just throw an exception. It's up to the calling application to print the
stack trace, if it wants.

2) There are utility methods, e.g. noStateChangeLOB, to create new
SQLExceptions, creating an exception like this will not include a
SQLState and will not link the original IOException to the SQLException.

Thanks,
Dan.

Tomohito Nakayama made changes - 29/Nov/05 11:29 PM
Status Resolved [ 5 ] Reopened [ 4 ]
Resolution Fixed [ 1 ]
Tomohito Nakayama added a comment - 03/Dec/05 03:12 PM
Description of patch :
   I judged that SQLException should not be thrown in InputStream#close/Reader#close.
   I remove calling resetStream method from close method and
     implemented Resetable interface in UTF8Reader and BinaryToRawStream and
     reset them from EmbedResultSet.

Test of patch:
   I executed derbyall and does not found new error.

Tomohito Nakayama made changes - 03/Dec/05 03:12 PM
Attachment DERBY-721_3.patch [ 12321109 ]
Tomohito Nakayama added a comment - 08/Dec/05 08:08 PM
http://mail-archives.apache.org/mod_mbox/db-derby-dev/200512.mbox/%3c43971A11.3070909@sbcglobal.net%3e

As discussed in series of mail refered by URL above ,
it should be restricted to get InputStream for same value in result row twice from a ResultSet .


Tomohito Nakayama added a comment - 08/Dec/05 10:36 PM
Description of this patch :
  This patch rollback DERBY-721.patch and DERBY-721_2.patch .

Test :
  Executed derbyall and found no error .

Tomohito Nakayama made changes - 08/Dec/05 10:36 PM
Attachment DERBY-721_rollback_1+2.patch [ 12321226 ]
Repository Revision Date User Message
ASF #355437 Fri Dec 09 10:20:02 UTC 2005 tmnk - rollback DERBY-721 and DERBY-721_2 because they will implicitly restrict spec of network driver. - Patch by Tomohito Nakayama (tomonaka@basil.ocn.ne.jp)
Files Changed
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/BinaryToRawStream.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java

Tomohito Nakayama added a comment - 09/Dec/05 07:22 PM
I commited DERBY-721_rollback_1+2.patch .

Sending java/engine/org/apache/derby/impl/jdbc/BinaryToRawStream.java
Sending java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
Sending java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java
Sending java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out
Sending java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
Sending java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java
Transmitting file data ......
Committed revision 355437.

Tomohito Nakayama added a comment - 16/Dec/05 12:05 AM
Description of patch :
 What is done:
  1: Throw newly defined exception when stream for same column in result was retrieved from a resultset , both in embed and network client.
  2: Add new test code for 1.

 What is *not* done:
  I think these should be considered in other patch/issue.
  1:Exception was *not* thrown when stream for same column in result was retrieved from Blob/Clob .
  2:Exception was *not* thrown when value , other than stream , was retrieved from result set ,after stream for the same column was retrieved.


Test:
 Executed derbyall and found no error except found in regression test .

Tomohito Nakayama made changes - 16/Dec/05 12:05 AM
Attachment DERBY-721_4.patch [ 12321345 ]
Tomohito Nakayama added a comment - 16/Dec/05 12:08 AM
I add one more description for the patch:
  What is done:
    3: Modify several test code to confirm 1.

Repository Revision Date User Message
ASF #357435 Sun Dec 18 05:15:39 UTC 2005 tmnk - DERBY-721_4 - State of InputStream retrieved from resultset is not clean , if there exists previous InputStream . Patch to throw exception if user get stream for a value in result set twice . by Tomohito Nakayama (tomonaka@basil.ocn.ne.jp)
Files Changed
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/LOBTest.out
ADD /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/Stream.out
ADD /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/Stream.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/LOBTest.out
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/SQLState.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/LOBTest.out
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/connectionJdbc20.out
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LOBTest.java
MODIFY /db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/connectionJdbc20.java
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties
ADD /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/Stream.out

Tomohito Nakayama added a comment - 18/Dec/05 02:18 PM
Committed .

Sending java/client/org/apache/derby/client/am/ResultSet.java
Sending java/engine/org/apache/derby/iapi/reference/SQLState.java
Sending java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
Sending java/engine/org/apache/derby/loc/messages_en.properties
Sending java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/LOBTest.out
Sending java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/LOBTest.out
Adding java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/Stream.out
Sending java/testing/org/apache/derbyTesting/functionTests/master/LOBTest.out
Adding java/testing/org/apache/derbyTesting/functionTests/master/Stream.out
Sending java/testing/org/apache/derbyTesting/functionTests/master/connectionJdbc20.out
Sending java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
Sending java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LOBTest.java
Adding java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/Stream.java
Sending java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/connectionJdbc20.java
Sending java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java
Transmitting file data ...............
Committed revision 357435.

Tomohito Nakayama made changes - 18/Dec/05 02:18 PM
Resolution Fixed [ 1 ]
Status Reopened [ 4 ] Resolved [ 5 ]
Tomohito Nakayama added a comment - 19/Dec/05 11:55 PM

Tomohito Nakayama made changes - 19/Dec/05 11:55 PM
Status Resolved [ 5 ] Reopened [ 4 ]
Resolution Fixed [ 1 ]
Tomohito Nakayama added a comment - 19/Dec/05 11:59 PM
Description of patch :
   Add master .out file for using DB2 universal driver .

Test :
   Execute derbyall with classpath contains db2jcc.jar and db2jcc_license_c.jar , and found no error .

Tomohito Nakayama made changes - 19/Dec/05 11:59 PM
Attachment DERBY-721_5.patch [ 12321427 ]
Tomohito Nakayama added a comment - 20/Dec/05 12:08 AM
I updated Component/s ...

Tomohito Nakayama made changes - 20/Dec/05 12:08 AM
Component/s Unknown [ 11400 ]
Component/s JDBC [ 11407 ]
Component/s Network Client [ 11690 ]
Repository Revision Date User Message
ASF #357966 Tue Dec 20 12:09:51 UTC 2005 tmnk - DERBY-721_5 State of InputStream retrieved from resultset is not clean , if there exists previous InputStream . Add mater .out file to be passed using DB2 universal driver. - Patch by Tomohito Nakayama (tomonaka@basil.ocn.ne.jp)
Files Changed
ADD /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/Stream.out

Tomohito Nakayama added a comment - 20/Dec/05 09:10 PM
Committed.

Adding java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/Stream.out
Transmitting file data .
Committed revision 357966.

Tomohito Nakayama made changes - 20/Dec/05 09:10 PM
Status Reopened [ 4 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Kathey Marsden made changes - 27/Jan/06 01:34 PM
Link This issue relates to DERBY-880 [ DERBY-880 ]
Kathey Marsden made changes - 10/Apr/06 02:40 AM
Fix Version/s 10.2.0.0 [ 11187 ]
Kathey Marsden added a comment - 19/Jul/06 05:38 PM
I think this change may affect existing applicaitons. Because of the fact that the InputStream retrieved from resultset is not clean , we now throw an exception if the user gest the stream for a value in result set twice.

Typically this would mean they were getting wrong results before if they retrieved the stream more than once. Now they will get an exception which is correct but may be surprising to users that are now seeing this new symptom. A formal release note still needs to be added.

Kathey Marsden made changes - 19/Jul/06 05:38 PM
Derby Info [Existing Application Impact, Release Note Needed]
Andrew McIntyre added a comment - 13/Dec/07 09:04 AM
This issue has been resolved for over a year with no further movement. Closing.

Andrew McIntyre made changes - 13/Dec/07 09:04 AM
Status Resolved [ 5 ] Closed [ 6 ]
Dag H. Wanvik made changes - 30/Jun/09 04:12 PM
Issue & fix info [Release Note Needed, Existing Application Impact] [Release Note Needed]