From 025527ab9fa0e17bb188aabbe2078a2477ab59da Mon Sep 17 00:00:00 2001 From: alanb Date: Fri, 28 Jan 2011 13:26:14 +0000 Subject: [PATCH] 7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420 Reviewed-by: chegar --- test/java/net/Socks/SocksProxyVersion.java | 36 +++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/test/java/net/Socks/SocksProxyVersion.java b/test/java/net/Socks/SocksProxyVersion.java index 19298e59c..fe4f1c65b 100644 --- a/test/java/net/Socks/SocksProxyVersion.java +++ b/test/java/net/Socks/SocksProxyVersion.java @@ -36,15 +36,22 @@ import java.io.DataInputStream; import java.io.IOException; public class SocksProxyVersion implements Runnable { - ServerSocket ss; + final ServerSocket ss; volatile boolean failed; public static void main(String[] args) throws Exception { new SocksProxyVersion(); } + @SuppressWarnings("try") public SocksProxyVersion() throws Exception { ss = new ServerSocket(0); + try (ServerSocket socket = ss) { + runTest(); + } + } + + void runTest() throws Exception { int port = ss.getLocalPort(); Thread serverThread = new Thread(this); serverThread.start(); @@ -75,22 +82,21 @@ public class SocksProxyVersion implements Runnable { } public void run() { - try (ss) { - Socket s = ss.accept(); - int version = (s.getInputStream()).read(); - if (version != 4) { - System.out.println("Got " + version + ", expected 4"); - failed = true; + try { + try (Socket s = ss.accept()) { + int version = (s.getInputStream()).read(); + if (version != 4) { + System.out.println("Got " + version + ", expected 4"); + failed = true; + } } - s.close(); - - s = ss.accept(); - version = (s.getInputStream()).read(); - if (version != 5) { - System.out.println("Got " + version + ", expected 5"); - failed = true; + try (Socket s = ss.accept()) { + int version = (s.getInputStream()).read(); + if (version != 5) { + System.out.println("Got " + version + ", expected 5"); + failed = true; + } } - s.close(); } catch (IOException e) { e.printStackTrace(); } -- GitLab