You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by gh...@apache.org on 2006/05/19 13:52:18 UTC
svn commit: r407775 - in
/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io:
FileInputStream.java FileOutputStream.java
Author: gharley
Date: Fri May 19 04:52:17 2006
New Revision: 407775
URL: http://svn.apache.org/viewvc?rev=407775&view=rev
Log:
HARMONY 479 : FileInputStream and FileOutputStream might cause Finalizer thread suspending
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileOutputStream.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java?rev=407775&r1=407774&r2=407775&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java Fri May 19 04:52:17 2006
@@ -139,17 +139,39 @@
* @throws IOException
* If an error occurs attempting to close this FileInputStream.
*/
- public void close() throws IOException {
- synchronized (channel) {
+ public void close() throws IOException {
+ if (fd == null) {
+ // if fd is null, then the underlying file is not opened, so nothing
+ // to close
+ return;
+ }
+ if (channel == null) {
+ /*
+ * if channel is null, then the channel doesn't need be taken care
+ * of but the underlying file has been opened
+ */
synchronized (this) {
- //FIXME: System.in, out, err may not want to be closed?
- if (channel.isOpen() && fd.descriptor >= 0) {
- channel.close();
+ if (fd.descriptor >= 0) {
+ fileSystem.close(fd.descriptor);
}
fd.descriptor = -1;
}
+ } else {
+ /*
+ * if the FileInputStream is constructed sucessfully, then channel
+ * must be closed, which will close the underlying file
+ */
+ synchronized (channel) {
+ synchronized (this) {
+ // FIXME: System.in, out, err may not want to be closed?
+ if (channel.isOpen() && fd.descriptor >= 0) {
+ channel.close();
+ }
+ fd.descriptor = -1;
+ }
+ }
}
- }
+ }
/**
* This method ensures that all resources for this file are released when it
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileOutputStream.java?rev=407775&r1=407774&r2=407775&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileOutputStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileOutputStream.java Fri May 19 04:52:17 2006
@@ -162,17 +162,39 @@
* @throws IOException
* If an error occurs attempting to close this FileOutputStream.
*/
- public void close() throws IOException {
- synchronized (channel) {
+ public void close() throws IOException {
+ if (fd == null) {
+ // if fd is null, then the underlying file is not opened, so nothing
+ // to close
+ return;
+ }
+ if (channel == null) {
+ /*
+ * if channel is null, then the channel doesn't need be taken care
+ * of but the underlying file has been opened
+ */
synchronized (this) {
- //FIXME: System.in, out, err may not want to be closed?
- if(channel.isOpen() && fd.descriptor >= 0){
- channel.close();
+ if (fd.descriptor >= 0) {
+ fileSystem.close(fd.descriptor);
}
fd.descriptor = -1;
}
+ } else {
+ /*
+ * if the FileOutputStream is constructed sucessfully, then channel
+ * must be closed, which will close the underlying file
+ */
+ synchronized (channel) {
+ synchronized (this) {
+ // FIXME: System.in, out, err may not want to be closed?
+ if (channel.isOpen() && fd.descriptor >= 0) {
+ channel.close();
+ }
+ fd.descriptor = -1;
+ }
+ }
}
- }
+ }
/**
* Frees any resources allocated to represent this FileOutputStream before