harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r938199 - in /harmony/enhanced/java/trunk/classlib/modules: luni/src/main/native/luni/unix/ nio/src/main/java/common/org/apache/harmony/nio/internal/ nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/
Date Mon, 26 Apr 2010 19:07:36 GMT
Author: hindessm
Date: Mon Apr 26 19:07:35 2010
New Revision: 938199

URL: http://svn.apache.org/viewvc?rev=938199&view=rev
Log:
Remove bogus size() == 0 check from FileChannelImpl.read(ByteBuffer[],...).
Add regression test (unix only - windows patches welcome) to show why it is
wrong.
Fix readv natives to return -1 on EOF as the read version does.  (I think
windows already does this.)

Modified:
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c
    harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
    harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c?rev=938199&r1=938198&r2=938199&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c
Mon Apr 26 19:07:35 2010
@@ -188,7 +188,7 @@ JNIEXPORT jlong JNICALL Java_org_apache_
     (*env)->ReleaseIntArrayElements(env, jlengths, lengths, JNI_ABORT);
   }
   hymem_free_memory(vectors);
-  return totalRead;
+  return totalRead == 0 ? -1 : totalRead;
 }
 
 /*

Modified: harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java?rev=938199&r1=938198&r2=938199&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
Mon Apr 26 19:07:35 2010
@@ -301,9 +301,6 @@ public abstract class FileChannelImpl ex
         if (calculateTotalRemaining(buffers, offset, length) == 0) {
             return 0;
         }
-        if (size() == 0) {
-            return -1;
-        }
         ByteBuffer[] directBuffers = new ByteBuffer[length];
         long[] handles = new long[length];
         int[] offsets = new int[length];

Modified: harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelTest.java?rev=938199&r1=938198&r2=938199&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelTest.java
Mon Apr 26 19:07:35 2010
@@ -516,6 +516,21 @@ public class FileChannelTest extends Tes
         writeDataToFile(fileOfReadOnlyFileChannel);
         assertEquals(fileOfReadOnlyFileChannel.length(), readOnlyFileChannel
                 .size());
+
+
+        // REGRESSION test for read(ByteBuffer[], int, int) on special files
+        try {
+            FileChannel specialFile =
+                new FileInputStream("/dev/zero").getChannel();
+            assertEquals(0, specialFile.size());
+            ByteBuffer buf = ByteBuffer.allocate(8);
+            assertEquals(8, specialFile.read(buf));
+            ByteBuffer[] bufs = { ByteBuffer.allocate(8) };
+            assertEquals(8, specialFile.read(bufs, 0, 1));
+            specialFile.close();
+        } catch (FileNotFoundException e) {
+            // skip test if special file doesn't exist
+        }
     }
 
     /**



Mime
View raw message