harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r440087 - in /incubator/harmony/enhanced/classlib/trunk/modules: luni/src/main/java/java/io/ nio/src/main/java/org/apache/harmony/nio/internal/
Date Mon, 04 Sep 2006 14:24:30 GMT
Author: mloenko
Date: Mon Sep  4 07:24:29 2006
New Revision: 440087

URL: http://svn.apache.org/viewvc?view=rev&rev=440087
Log:
applied patch for HARMONY-826
[classlib][io] unexpected IOException for new FileInputStream(FileDescriptor.in).close();

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
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/FileChannelImpl.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?view=diff&rev=440087&r1=440086&r2=440087
==============================================================================
--- 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
Mon Sep  4 07:24:29 2006
@@ -39,6 +39,8 @@
     // initialized).
     private FileChannel channel;
 
+    boolean innerFD;
+
     private IFileSystem fileSystem = Platform.getFileSystem();
 
     private Object repositioningLock = new Object();
@@ -67,6 +69,7 @@
         fd = new FileDescriptor();
         fd.descriptor = fileSystem.open(file.properPath(true),
                 IFileSystem.O_RDONLY);
+		innerFD = true;
         channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
                 IFileSystem.O_RDONLY);
     }
@@ -93,6 +96,7 @@
             security.checkRead(fd);
         }
         this.fd = fd;
+        innerFD = false;
         channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
                 IFileSystem.O_RDONLY);
     }
@@ -155,30 +159,17 @@
             // 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) {
-                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
-             */
+        if (channel != null) {
             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;
+                if (channel.isOpen()) {
+                    channel.close();
                 }
+            }
+        }
+	synchronized (this) {
+            if (fd.descriptor >= 0 && innerFD) {
+                fileSystem.close(fd.descriptor);
+                fd.descriptor = -1;
             }
         }
     }

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?view=diff&rev=440087&r1=440086&r2=440087
==============================================================================
--- 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
Mon Sep  4 07:24:29 2006
@@ -41,7 +41,9 @@
 	 */
 	FileDescriptor fd;
 
-	// The unique file channel associated with this FileInputStream (lazily
+    boolean innerFD;
+
+    // The unique file channel associated with this FileInputStream (lazily
 	// initialized).
 	private FileChannel channel;
 
@@ -91,6 +93,7 @@
         }
 		fd = new FileDescriptor();
         fd.descriptor = fileSystem.open(file.properPath(true), append?IFileSystem.O_APPEND:IFileSystem.O_WRONLY);
+        innerFD = true;
         channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
                 append? IFileSystem.O_APPEND:IFileSystem.O_WRONLY);
 	}
@@ -116,6 +119,7 @@
             security.checkWrite(fd);
         }
         this.fd = fd;
+        innerFD = false;
         channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
                 IFileSystem.O_WRONLY);
 	}
@@ -171,43 +175,31 @@
             // 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) {
-                if (fd.descriptor >= 0) {
-                    fileSystem.close(fd.descriptor);
-                }
-                fd.descriptor = -1;
-            }
-        } else {
-            /*
-             * if the FileOutputStream is constructed successfully, then channel
-             * must be closed, which will close the underlying file
-             */
+
+        if (channel != null) {
             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;
+                if (channel.isOpen() && fd.descriptor >= 0) {
+                    channel.close();
                 }
             }
         }
+
+        synchronized (this) {
+            if (fd.descriptor >= 0 && innerFD) {
+                fileSystem.close(fd.descriptor);
+                fd.descriptor = -1;
+            }
+        }
     }
 
 	/**
-	 * Frees any resources allocated to represent this FileOutputStream before
-	 * it is garbage collected. This method is called from the Java Virtual
-	 * Machine.
-	 * 
-	 * @throws IOException
-	 *             If an error occurs attempting to finalize this
-	 *             FileOutputStream.
-	 */
+     * Frees any resources allocated to represent this FileOutputStream before
+     * it is garbage collected. This method is called from the Java Virtual
+     * Machine.
+     * 
+     * @throws IOException If an error occurs attempting to finalize this
+     *         FileOutputStream.
+     */
 	@Override
     protected void finalize() throws IOException {
 		close();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java?view=diff&rev=440087&r1=440086&r2=440087
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java
Mon Sep  4 07:24:29 2006
@@ -147,10 +147,13 @@
      */
     public void close() throws IOException {
         synchronized (channel) {
-            synchronized (this) {
-                if (channel.isOpen() && fd.descriptor >= 0) {
-                    channel.close();
-                }
+            if (channel.isOpen()) {
+                channel.close();
+            }
+        }
+        synchronized (this) {
+            if (fd != null && fd.descriptor >= 0) {
+                fileSystem.close(fd.descriptor);
                 fd.descriptor = -1;
             }
         }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/FileChannelImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/FileChannelImpl.java?view=diff&rev=440087&r1=440086&r2=440087
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/FileChannelImpl.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/FileChannelImpl.java
Mon Sep  4 07:24:29 2006
@@ -97,7 +97,6 @@
         if (stream instanceof Closeable) {
             ((Closeable) stream).close();
         }
-		fileSystem.close(handle);
 	}
 
 	protected FileLock basicLock(long position, long size, boolean shared,



Mime
View raw message