OK, the new patch is below. I left "fInputStream=null" in close(). There are a
few places in ChunkyByteArray where fInputStream is tested for null as an
indication of whether the stream has been closed. I think they're perfectly
valid since much of java.io does exactly the same thing.
george
*** xml-xerces/java/src/org/apache/xerces/utils/ChunkyByteArray.java Tue Jan
25
19:26:44 2000
--- src/org/apache/xerces/utils/ChunkyByteArray.java Mon Feb 07 22:13:52 2000
***************
*** 109,116 ****
int b = (int)(fData[0][fOffset]);
if (++fOffset == fLength) {
fData = null;
- if (fLength < CHUNK_SIZE)
- fInputStream = null;
}
return b;
}
--- 109,114 ----
***************
*** 134,141 ****
byte[] chunk = fData[0];
if (length >= bytesLeft) {
length = bytesLeft;
- if (fLength < CHUNK_SIZE)
- fInputStream = null;
}
if (buffer == null) {
fOffset += length;
--- 132,137 ----
***************
*** 209,216 ****
result = fInputStream.read(data, offset, capacity);
if (result == -1) {
data[offset] = (byte)0xff;
- fInputStream.close();
- fInputStream = null;
break;
}
if (result > 0) {
--- 205,210 ----
***************
*** 220,225 ****
--- 214,225 ----
}
} while (capacity > 0);
}
+ public void close() throws IOException
+ {
+ if (fInputStream == null) return;
+ fInputStream.close();
+ fInputStream=null;
+ }
//
// Chunk size constants
//
-----Original Message-----
From: Andy Clark [mailto:[EMAIL PROTECTED]
Sent: Monday, February 07, 2000 7:50 PM
To: [EMAIL PROTECTED]
Subject: Re: Patch for ChunkyByteArray.java
"George T. Joseph" wrote:
> ChunkyByteArray didn't have a close() method so if
> ChunkyByteArray.close() were called (and it IS being
> called properly), it would be InputStream.close() that
> was actually invoked. That's an empty method and
> therefore a leak.
You are absolutely correct. This needs to be fixed.
> So, I'll remove the calls to close() in ChunkyByteArray,
> but the close() method itself needs to stay. Also, the
> existing "fInputStream = null" statements have
> to stay removed so close() can call fInputStream.close().
Exactly. In fact, the fInputStream field should never be
set to null. But we need to make sure that there is no
code that relies on the fact that the field is null in
order to operate correctly. We may be fine just removing
the assignments to null, though.
--
Andy Clark * IBM, JTC - Silicon Valley * [EMAIL PROTECTED]