Skip to content

Commit 6293299

Browse files
c-clearyAlekseiEfimov
authored andcommitted
8264824: java/net/Inet6Address/B6206527.java doesn't close ServerSocket properly
Reviewed-by: aefimov, dfuchs, michaelm, vtewari
1 parent 6b90715 commit 6293299

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

test/jdk/java/net/Inet6Address/B6206527.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,22 +40,24 @@ public class B6206527 {
4040
public static void main (String[] args) throws Exception {
4141
Inet6Address addr = getLocalAddr();
4242
if (addr == null) {
43-
System.out.println ("Could not find a link-local address");
43+
System.out.println("Could not find a link-local address");
4444
return;
4545
}
4646

47-
ServerSocket ss = new ServerSocket();
48-
System.out.println ("trying LL addr: " + addr);
49-
ss.bind(new InetSocketAddress(addr, 0));
47+
try (ServerSocket ss = new ServerSocket()) {
48+
System.out.println("trying LL addr: " + addr);
49+
ss.bind(new InetSocketAddress(addr, 0));
50+
}
5051

5152
// need to remove the %scope suffix
52-
addr = (Inet6Address)InetAddress.getByAddress (
53+
addr = (Inet6Address) InetAddress.getByAddress (
5354
addr.getAddress()
5455
);
5556

56-
System.out.println ("trying LL addr: " + addr);
57-
ss = new ServerSocket();
58-
ss.bind(new InetSocketAddress(addr, 0));
57+
try (ServerSocket ss = new ServerSocket()) {
58+
System.out.println("trying LL addr: " + addr);
59+
ss.bind(new InetSocketAddress(addr, 0));
60+
}
5961
}
6062

6163
public static Inet6Address getLocalAddr() throws Exception {

0 commit comments

Comments
 (0)