harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r1000005 - in /harmony/enhanced/java/trunk/classlib/modules/luni/src: main/java/java/io/ main/native/luni/shared/ main/native/luni/unix/ main/native/luni/windows/ test/api/common/org/apache/harmony/luni/tests/java/io/
Date Wed, 22 Sep 2010 14:49:05 GMT
Author: tellison
Date: Wed Sep 22 14:49:04 2010
New Revision: 1000005

URL: http://svn.apache.org/viewvc?rev=1000005&view=rev
Log:
Apply patch for HARMONY-6642 ([classlib][luni] FileInputStream doesn't close FD in native
code)

Modified:
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileDescriptor.java
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileInputStream.java
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileOutputStream.java
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/filedesc.c
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/exports.txt
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/helpers.c
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/helpers.h
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/helpers.c
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/helpers.h
    harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileDescriptor.java?rev=1000005&r1=1000004&r2=1000005&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileDescriptor.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileDescriptor.java
Wed Sep 22 14:49:04 2010
@@ -62,10 +62,16 @@ public final class FileDescriptor {
 
     private static native void oneTimeInitialization();
 
+    private static native long getStdInDescriptor();
+    
+    private static native long getStdOutDescriptor();
+    
+    private static native long getStdErrDescriptor();
+
     static {
-        in.descriptor = 0;
-        out.descriptor = 1;
-        err.descriptor = 2;
+        in.descriptor = getStdInDescriptor();
+        out.descriptor = getStdOutDescriptor();
+        err.descriptor = getStdErrDescriptor();
 
         oneTimeInitialization();
     }

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileInputStream.java?rev=1000005&r1=1000004&r2=1000005&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileInputStream.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileInputStream.java
Wed Sep 22 14:49:04 2010
@@ -45,8 +45,6 @@ public class FileInputStream extends Inp
     // initialized).
     private FileChannel channel;
 
-    boolean innerFD;
-
     private IFileSystem fileSystem = Platform.getFileSystem();
 
     private static class RepositioningLock {
@@ -81,7 +79,6 @@ public class FileInputStream extends Inp
         fd.readOnly = true;
         fd.descriptor = fileSystem.open(file.properPath(true),
                 IFileSystem.O_RDONLY);
-        innerFD = true;
         channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
                 IFileSystem.O_RDONLY);
     }
@@ -109,7 +106,6 @@ public class FileInputStream extends Inp
             security.checkRead(fd);
         }
         this.fd = fd;
-        innerFD = false;
         channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
                 IFileSystem.O_RDONLY);
     }
@@ -173,7 +169,7 @@ public class FileInputStream extends Inp
             }
         }
         synchronized (this) {
-            if (fd.descriptor >= 0 && innerFD) {
+            if (fd.descriptor >= 0) {
                 fileSystem.close(fd.descriptor);
                 fd.descriptor = -1;
             }

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileOutputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileOutputStream.java?rev=1000005&r1=1000004&r2=1000005&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileOutputStream.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileOutputStream.java
Wed Sep 22 14:49:04 2010
@@ -42,8 +42,6 @@ public class FileOutputStream extends Ou
      */
     FileDescriptor fd;
 
-    boolean innerFD;
-
     // The unique file channel associated with this FileInputStream (lazily
     // initialized).
     private FileChannel channel;
@@ -94,7 +92,6 @@ public class FileOutputStream extends Ou
         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);
     }
@@ -123,7 +120,6 @@ public class FileOutputStream extends Ou
             security.checkWrite(fd);
         }
         this.fd = fd;
-        innerFD = false;
         channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
                 IFileSystem.O_WRONLY);
     }
@@ -190,7 +186,7 @@ public class FileOutputStream extends Ou
         }
 
         synchronized (this) {
-            if (fd.descriptor >= 0 && innerFD) {
+            if (fd.descriptor >= 0) {
                 fileSystem.close(fd.descriptor);
                 fd.descriptor = -1;
             }

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/filedesc.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/filedesc.c?rev=1000005&r1=1000004&r2=1000005&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/filedesc.c
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/filedesc.c
Wed Sep 22 14:49:04 2010
@@ -19,6 +19,7 @@
 #include "nethelp.h"
 #include "exceptions.h"
 #include "harmonyglob.h"
+#include "helpers.h"
 
 JNIEXPORT void JNICALL
 Java_java_io_FileDescriptor_syncImpl (JNIEnv * env, jobject recv)
@@ -57,3 +58,21 @@ Java_java_io_FileDescriptor_oneTimeIniti
     return;
   HARMONY_CACHE_SET (env, FID_java_io_FileDescriptor_descriptor, descriptorFID);
 }
+
+JNIEXPORT jlong JNICALL
+Java_java_io_FileDescriptor_getStdInDescriptor (JNIEnv * env, jclass fdClazz)
+{
+  return getPlatformStdInFD();
+}
+
+JNIEXPORT jlong JNICALL
+Java_java_io_FileDescriptor_getStdOutDescriptor (JNIEnv * env, jclass fdClazz)
+{
+  return getPlatformStdOutFD();
+}
+
+JNIEXPORT jlong JNICALL
+Java_java_io_FileDescriptor_getStdErrDescriptor (JNIEnv * env, jclass fdClazz)
+{
+  return getPlatformStdErrFD();
+}

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/exports.txt
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/exports.txt?rev=1000005&r1=1000004&r2=1000005&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/exports.txt
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/exports.txt
Wed Sep 22 14:49:04 2010
@@ -42,6 +42,9 @@ Java_java_io_File_renameToImpl
 Java_java_io_File_rootsImpl
 Java_java_io_File_setLastModifiedImpl
 Java_java_io_File_setReadOnlyImpl
+Java_java_io_FileDescriptor_getStdErrDescriptor
+Java_java_io_FileDescriptor_getStdInDescriptor
+Java_java_io_FileDescriptor_getStdOutDescriptor
 Java_java_io_FileDescriptor_oneTimeInitialization
 Java_java_io_FileDescriptor_syncImpl
 Java_java_io_ObjectStreamClass_getConstructorSignature

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/helpers.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/helpers.c?rev=1000005&r1=1000004&r2=1000005&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/helpers.c
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/helpers.c
Wed Sep 22 14:49:04 2010
@@ -252,3 +252,13 @@ void getOSCharset(char *locale, const si
   }
   return;
 }
+
+jlong getPlatformStdInFD() {
+  return (jlong)0;
+}
+jlong getPlatformStdOutFD() {
+  return (jlong)1;
+}
+jlong getPlatformStdErrFD() {
+  return (jlong)2;
+}

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/helpers.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/helpers.h?rev=1000005&r1=1000004&r2=1000005&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/helpers.h
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/helpers.h
Wed Sep 22 14:49:04 2010
@@ -35,4 +35,7 @@ I_32 setPlatformLastModified (JNIEnv * e
 I_32 setPlatformReadOnly (JNIEnv * env, char *path);
 int portCmp (const void **a, const void **b);
 void getOSCharset(char *locale, const size_t size);
+jlong getPlatformStdInFD();
+jlong getPlatformStdOutFD();
+jlong getPlatformStdErrFD();
 #endif /* helpers_h */

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/helpers.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/helpers.c?rev=1000005&r1=1000004&r2=1000005&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/helpers.c
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/helpers.c
Wed Sep 22 14:49:04 2010
@@ -15,6 +15,11 @@
  *  limitations under the License.
  */
 
+/* windows.h defined UDATA.  Ignore its definition */
+#define UDATA UDATA_win32_
+#include <windows.h>
+#undef UDATA                    /* this is safe because our UDATA is a typedef, not a macro
*/
+
 /* Undefine the winsockapi because winsock2 defines it.  Removes warnings. */
 #if defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_)
 #undef _WINSOCKAPI_
@@ -446,3 +451,13 @@ void getOSCharset(char *locale, const si
   getCharset(cp, locale, size);
   return;
 }
+
+jlong getPlatformStdInFD() {
+  return (jlong)GetStdHandle(STD_INPUT_HANDLE);
+}
+jlong getPlatformStdOutFD() {
+  return (jlong)GetStdHandle(STD_OUTPUT_HANDLE);
+}
+jlong getPlatformStdErrFD() {
+  return (jlong)GetStdHandle(STD_ERROR_HANDLE);
+}

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/helpers.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/helpers.h?rev=1000005&r1=1000004&r2=1000005&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/helpers.h
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/helpers.h
Wed Sep 22 14:49:04 2010
@@ -34,4 +34,7 @@ void setPlatformBindOptions (JNIEnv * en
 I_32 setPlatformLastModified (JNIEnv * env, char *path, I_64 time);
 I_32 setPlatformReadOnly (JNIEnv * env, char *path);
 void getOSCharset(char *locale, const size_t size);
+jlong getPlatformStdInFD();
+jlong getPlatformStdOutFD();
+jlong getPlatformStdErrFD();
 #endif /* helpers_h */

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java?rev=1000005&r1=1000004&r2=1000005&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java
Wed Sep 22 14:49:04 2010
@@ -18,6 +18,7 @@
 package org.apache.harmony.luni.tests.java.io;
 
 import java.io.File;
+import java.io.FileDescriptor;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
@@ -121,6 +122,31 @@ public class FileInputStreamTest extends
         } catch (IOException e) {
             // Expected
         }
+        
+        // Regression test for HARMONY-6642
+        FileInputStream fis = new FileInputStream(fileName);
+        FileInputStream fis2 = new FileInputStream(fis.getFD());
+        try {
+            fis2.close();
+            fis.read();
+            fail("Able to read from closed fd");
+        } catch (IOException e) {
+            // Expected
+        } finally {
+            try {
+                fis.close();
+            } catch (IOException e) {}
+        }
+        
+        FileInputStream stdin = new FileInputStream(FileDescriptor.in);
+        stdin.close();
+        stdin = new FileInputStream(FileDescriptor.in);
+        try {
+            stdin.read();
+            fail("Able to read from stdin after close");
+        } catch (IOException e) {
+            // Expected
+        }
     }
 
     /**



Mime
View raw message