|
Quick Lists
|
|
Bug ID:
|
4257700
|
|
Votes
|
0
|
|
Synopsis
|
java.net.URLConnection.connect() causes leak of file descriptors
|
|
Category
|
java:classes_net
|
|
Reported Against
|
kestrel
|
|
Release Fixed
|
|
|
State
|
11-Closed,
Not a Defect,
request for enhancement
|
|
Priority:
|
2-High
|
|
Related Bugs
|
4240957
,
4240960
,
4240969
,
4240971
,
4299683
|
|
Submit Date
|
28-JUL-1999
|
|
Description
|
sun.net.www.protocol.file.FileURLConnection.connect() opens up
a file input stream and does not close it :
---- code of FileURLConnection.connect() -------------
public void connect() throws IOException {
if (!connected) {
try {
String decodedPath = ParseUtil.decode(url.getPath());
file = new File(decodedPath.replace('/', File.separatorChar));
filename = file.toString();
isDirectory = file.isDirectory();
if (isDirectory) {
files = (List) Arrays.asList(file.list());
} else {
is = new BufferedInputStream(new FileInputStream(filename));
}
} catch (IOException e) {
throw e;
}
connected = true;
}
}
------
java.net.URLConnection API does not have disconnect() method. That means there is no way to
close a file connection, which causes leak of file descriptors in some user applications.
======================================================================
|
|
Work Around
|
N/A
|
|
Evaluation
|
Even if we added a dispose() method as suggested, someone would
have to call it in order to free up the FileDescriptor before GC would
free it up. There is already a way to do this. Simply call close() on
the result of getInputStream() when you are done reading the file data.
The close() call will chain all the way down to the underlying
FileInputStream and close the file descriptor.
xxxxx@xxxxx 1999-07-28
|
|
Comments
|
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |