|
1 | 1 | /* |
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
@@ -40,22 +40,24 @@ public class B6206527 { |
40 | 40 | public static void main (String[] args) throws Exception { |
41 | 41 | Inet6Address addr = getLocalAddr(); |
42 | 42 | 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"); |
44 | 44 | return; |
45 | 45 | } |
46 | 46 |
|
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 | + } |
50 | 51 |
|
51 | 52 | // need to remove the %scope suffix |
52 | | - addr = (Inet6Address)InetAddress.getByAddress ( |
| 53 | + addr = (Inet6Address) InetAddress.getByAddress ( |
53 | 54 | addr.getAddress() |
54 | 55 | ); |
55 | 56 |
|
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 | + } |
59 | 61 | } |
60 | 62 |
|
61 | 63 | public static Inet6Address getLocalAddr() throws Exception { |
|
0 commit comments