harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r424240 - in /incubator/harmony/enhanced/classlib/trunk/modules/nio/src: main/java/org/apache/harmony/nio/internal/ test/java/common/org/apache/harmony/tests/java/nio/channels/
Date Fri, 21 Jul 2006 09:11:54 GMT
Author: pyang
Date: Fri Jul 21 02:11:54 2006
New Revision: 424240

URL: http://svn.apache.org/viewvc?rev=424240&view=rev
Log:
Fix for HARMONY-941 ([classlib][nio] compatibility: java.nio.channels.FileChannel.truncate,
transferTo throw different exeptions from RI)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/FileChannelImpl.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/ReadOnlyFileChannel.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java

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?rev=424240&r1=424239&r2=424240&view=diff
==============================================================================
--- 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
Fri Jul 21 02:11:54 2006
@@ -439,13 +439,14 @@
         if (!target.isOpen()) {
             throw new ClosedChannelException();
         }
+        if (target instanceof ReadOnlyFileChannel) {
+            throw new NonWritableChannelException();
+        }
         if (position < 0 || count < 0 || position > Integer.MAX_VALUE
                 || count > Integer.MAX_VALUE) {
             throw new IllegalArgumentException();
         }
-        if (target instanceof ReadOnlyFileChannel) {
-            throw new NonWritableChannelException();
-        }
+        
         if (count == 0 || position >= size()) {
             return 0;
         }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/ReadOnlyFileChannel.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/ReadOnlyFileChannel.java?rev=424240&r1=424239&r2=424240&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/ReadOnlyFileChannel.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/ReadOnlyFileChannel.java
Fri Jul 21 02:11:54 2006
@@ -56,6 +56,9 @@
 
 	public final FileChannel truncate(long size) throws IOException {
 		openCheck();
+        if (size < 0) {
+            throw new IllegalArgumentException();
+        }
 		throw new NonWritableChannelException();
 	}
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java?rev=424240&r1=424239&r2=424240&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java
Fri Jul 21 02:11:54 2006
@@ -555,6 +555,14 @@
      * @tests java.nio.channels.FileChannel#truncate(long)
      */
     public void test_truncateJ_IllegalArgument() throws Exception {
+        // regression test for Harmony-941
+        try {
+            readOnlyFileChannel.truncate(-1);
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
         try {
             writeOnlyFileChannel.truncate(-1);
             fail("should throw IllegalArgumentException");
@@ -2862,6 +2870,22 @@
         // size.
         try {
             readWriteFileChannel.transferTo(10, 10, readOnlyFileChannel);
+            fail("should throw NonWritableChannelException.");
+        } catch (NonWritableChannelException e) {
+            // expected
+        }
+        
+        // regression test for Harmony-941
+        // first throws NonWritableChannelException even arguments are illegal.
+        try {
+            readWriteFileChannel.transferTo(-1, 10, readOnlyFileChannel);
+            fail("should throw NonWritableChannelException.");
+        } catch (NonWritableChannelException e) {
+            // expected
+        }
+
+        try {
+            readWriteFileChannel.transferTo(0, -1, readOnlyFileChannel);
             fail("should throw NonWritableChannelException.");
         } catch (NonWritableChannelException e) {
             // expected



Mime
View raw message