[jboss-remoting-commits] JBoss Remoting SVN: r3849 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Wed Apr 2 00:20:20 EDT 2008


Author: ron.sigal at jboss.com
Date: 2008-04-02 00:20:20 -0400 (Wed, 02 Apr 2008)
New Revision: 3849

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/transport/PortUtil.java
Log:
JBREM-934: Put InetAddress.getByName() call in AccessController.doPrivileged() call.

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/PortUtil.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/PortUtil.java	2008-04-02 04:18:38 UTC (rev 3848)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/PortUtil.java	2008-04-02 04:20:20 UTC (rev 3849)
@@ -24,7 +24,6 @@
 
 import java.net.ServerSocket;
 import java.net.InetAddress;
-import java.net.Socket;
 import java.net.UnknownHostException;
 import java.io.IOException;
 import java.security.AccessController;
@@ -60,31 +59,38 @@
     * @param p
     * @return true if available, false if already in use
     */
-   public static boolean checkPort(final int p, String host)
+   public static boolean checkPort(final int p, final String host)
    {
       boolean available = true;
       ServerSocket socket = null;
+
       try
       {
-         final InetAddress inetAddress = InetAddress.getByName(host);
-
-         socket = (ServerSocket) AccessController.doPrivileged( new PrivilegedExceptionAction()
+         try
          {
-            public Object run() throws Exception
+            socket = (ServerSocket) AccessController.doPrivileged( new PrivilegedExceptionAction()
             {
-               return new ServerSocket(p, 0, inetAddress);
-            }
-         });
+               public Object run() throws Exception
+               {
+                  InetAddress inetAddress = InetAddress.getByName(host);
+                  return new ServerSocket(p, 0, inetAddress);
+               }
+            });
+         }
+         catch (PrivilegedActionException e)
+         {
+            available = false;
+            throw (IOException) e.getCause();
+         }
       }
-      catch (PrivilegedActionException e)
-      {
-         log.debug("port " + p + " already in use.  Will try another.", e.getCause());
-         available = false;
-      }
       catch (UnknownHostException e)
       {
          log.warn("unknown host: " + host);
       }
+      catch (IOException e)
+      {
+         log.debug("port " + p + " already in use.  Will try another.", e.getCause());
+      }
       finally
       {
          if(socket != null)




More information about the jboss-remoting-commits mailing list