harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r427892 - in /incubator/harmony/enhanced/classlib/trunk/modules/nio/src: main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java test/java/common/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java
Date Wed, 02 Aug 2006 04:55:06 GMT
Author: pyang
Date: Tue Aug  1 21:55:06 2006
New Revision: 427892

URL: http://svn.apache.org/viewvc?rev=427892&view=rev
Log:
Fix for HARMONY-1036 ([classlib][nio] DatagramChannel.socket().receive/send should throw IllegalBlockingModeException
when it is in non-blocking mode)

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java?rev=427892&r1=427891&r2=427892&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
Tue Aug  1 21:55:06 2006
@@ -29,6 +29,7 @@
 import java.nio.channels.AlreadyConnectedException;
 import java.nio.channels.ClosedChannelException;
 import java.nio.channels.DatagramChannel;
+import java.nio.channels.IllegalBlockingModeException;
 import java.nio.channels.NotYetConnectedException;
 import java.nio.channels.spi.SelectorProvider;
 
@@ -690,6 +691,26 @@
             channelImpl.isBound = true;
         }
 
+        /*
+         * @see java.net.DatagramSocket#receive(java.net.DatagramPacket)
+         */
+        public void receive(DatagramPacket packet) throws IOException {
+            if (!channelImpl.isBlocking()) {
+                throw new IllegalBlockingModeException();
+            }
+            super.receive(packet);
+        }
+
+        /*
+         * @see java.net.DatagramSocket#send(java.net.DatagramPacket)
+         */
+        public void send(DatagramPacket packet) throws IOException {
+            if (!channelImpl.isBlocking()) {
+                throw new IllegalBlockingModeException();
+            }
+            super.send(packet);
+        }
+        
         /*
          * @see java.net.DatagramSocket#close()
          */

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.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/DatagramChannelTest.java?rev=427892&r1=427891&r2=427892&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java
Tue Aug  1 21:55:06 2006
@@ -25,6 +25,7 @@
 import java.nio.channels.AsynchronousCloseException;
 import java.nio.channels.ClosedChannelException;
 import java.nio.channels.DatagramChannel;
+import java.nio.channels.IllegalBlockingModeException;
 import java.nio.channels.NotYetConnectedException;
 import java.nio.channels.UnresolvedAddressException;
 import java.nio.channels.UnsupportedAddressTypeException;
@@ -2551,6 +2552,28 @@
             fail("Should throw NullPointerException");
         } catch (NullPointerException e) {
             //pass
+        }
+    }
+    
+    /**
+     * @tests DatagramChannel#socket()
+     */
+    public void test_socket_IllegalBlockingModeException() throws Exception {
+        // regression test for Harmony-1036
+        DatagramChannel channel = DatagramChannel.open();
+        channel.configureBlocking(false);
+        DatagramSocket socket = channel.socket();
+        try {
+            socket.send(null);
+            fail("should throw IllegalBlockingModeException");
+        } catch (IllegalBlockingModeException e) {
+            // expected
+        }
+        try {
+            socket.receive(null);
+            fail("should throw IllegalBlockingModeException");
+        } catch (IllegalBlockingModeException e) {
+            // expected
         }
     }
     



Mime
View raw message