harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r981356 - in /harmony/enhanced/java/trunk/classlib/modules/nio/src: main/java/common/org/apache/harmony/nio/internal/ test/java/common/org/apache/harmony/nio/tests/java/nio/channels/
Date Mon, 02 Aug 2010 02:56:44 GMT
Author: regisxu
Date: Mon Aug  2 02:56:43 2010
New Revision: 981356

URL: http://svn.apache.org/viewvc?rev=981356&view=rev
Log:
Fix for HARMONY-6475: [classlib][nio] - Selector.open() throw AccessControlException when
SecurityManager is installed

Modified:
    harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/PipeImpl.java
    harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
    harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/PipeTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/PipeImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/PipeImpl.java?rev=981356&r1=981355&r2=981356&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/PipeImpl.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/PipeImpl.java
Mon Aug  2 02:56:43 2010
@@ -24,6 +24,10 @@ import java.nio.ByteBuffer;
 import java.nio.channels.Pipe;
 import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.spi.SelectorProvider;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 import org.apache.harmony.luni.platform.FileDescriptorHandler;
 
@@ -42,21 +46,30 @@ final class PipeImpl extends Pipe {
 
     public PipeImpl() throws IOException {
         super();
+        sink = new SinkChannelImpl(SelectorProvider.provider());
+        source = new SourceChannelImpl(SelectorProvider.provider());
         try {
-            sink = new SinkChannelImpl(SelectorProvider.provider());
-            source = new SourceChannelImpl(SelectorProvider.provider());
-            sink.finishConnect();
-            source.accept();
-            source.closeServer();
-        } catch(IOException ioe){
+            AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
+                public Void run() throws Exception {
+                    sink.finishConnect();
+                    source.accept();
+                    source.closeServer();
+                    return null;
+                }
+            });
+        } catch (PrivilegedActionException e) {
             reset();
-            throw ioe;
-        } catch(RuntimeException e){
-            reset();
-            throw e;
+            Exception ex = e.getException();
+            if (ex instanceof IOException) {
+                throw (IOException) ex;
+            }
+            if (ex instanceof RuntimeException) {
+                throw (RuntimeException) ex;
+            }
+            throw new RuntimeException(ex);
         }
     }
-    
+
     private void reset(){
         if(sink != null){
             try {

Modified: harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java?rev=981356&r1=981355&r2=981356&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
Mon Aug  2 02:56:43 2010
@@ -746,7 +746,7 @@ class SocketChannelImpl extends SocketCh
          */
         @Override
         public boolean isConnected() {
-            return channel.isConnected();
+            return super.isConnected() || channel.isConnected();
         }
 
         /**

Modified: harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/PipeTest.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/PipeTest.java?rev=981356&r1=981355&r2=981356&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/PipeTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/PipeTest.java
Mon Aug  2 02:56:43 2010
@@ -17,9 +17,11 @@
 package org.apache.harmony.nio.tests.java.nio.channels;
 
 import java.io.IOException;
+import java.net.NetPermission;
 import java.nio.channels.Pipe;
 import java.nio.channels.Pipe.SinkChannel;
 import java.nio.channels.Pipe.SourceChannel;
+import java.security.Permission;
 
 import junit.framework.TestCase;
 
@@ -36,6 +38,22 @@ public class PipeTest extends TestCase {
 		assertNotNull(pipe);
 	}
 	
+    /**
+     * @tests java.nio.channels.Pipe#open()
+     */
+    public void test_open_securityManager() throws IOException {
+        SecurityManager old = System.getSecurityManager();
+        SecurityManager sm = new MockSM();
+
+        try {
+            System.setSecurityManager(sm);
+            Pipe pipe = Pipe.open();
+            assertNotNull(pipe);
+        } finally {
+            System.setSecurityManager(old);
+        }
+    }
+
 	/**
 	 * @tests java.nio.channels.Pipe#sink()
 	 */
@@ -55,3 +73,17 @@ public class PipeTest extends TestCase {
 	}
 
 }
+
+class MockSM extends SecurityManager {
+    public void checkPermission(Permission permission) {
+        if (permission instanceof NetPermission) {
+            throw new SecurityException();
+        }
+
+        if (permission instanceof RuntimePermission) {
+            if ("setSecurityManager".equals(permission.getName())) {
+                return;
+            }
+        }
+    }
+}



Mime
View raw message