File tree Expand file tree Collapse file tree 1 file changed +3
-9
lines changed
java/client/src/org/openqa/selenium/net Expand file tree Collapse file tree 1 file changed +3
-9
lines changed Original file line number Diff line number Diff line change @@ -104,14 +104,10 @@ private static int createAcceptablePort() {
104
104
}
105
105
106
106
private static int checkPortIsFree (int port ) {
107
- ServerSocket socket ;
108
- try {
109
- socket = new ServerSocket ();
107
+ try (ServerSocket socket = new ServerSocket ()) {
110
108
socket .setReuseAddress (true );
111
109
socket .bind (new InetSocketAddress ("localhost" , port ));
112
- int localPort = socket .getLocalPort ();
113
- socket .close ();
114
- return localPort ;
110
+ return socket .getLocalPort ();
115
111
} catch (IOException e ) {
116
112
return -1 ;
117
113
}
@@ -120,10 +116,8 @@ private static int checkPortIsFree(int port) {
120
116
public static void waitForPortUp (int port , int timeout , TimeUnit unit ) {
121
117
long end = System .currentTimeMillis () + unit .toMillis (timeout );
122
118
while (System .currentTimeMillis () < end ) {
123
- try {
124
- Socket socket = new Socket ();
119
+ try (Socket socket = new Socket ()) {
125
120
socket .connect (new InetSocketAddress ("localhost" , port ), 1000 );
126
- socket .close ();
127
121
return ;
128
122
} catch (ConnectException | SocketTimeoutException e ) {
129
123
// Ignore this
You can’t perform that action at this time.
0 commit comments