aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Conor Cleary <ccleary@openjdk.org> 2021-04-15 14:05:55 +0000
committerGravatar Aleksei Efimov <aefimov@openjdk.org> 2021-04-15 14:05:55 +0000
commit6293299dd341721b33424c7012b1123bb267cabb (patch)
tree6fad35b242bc034f2f8361396c87613e68aa3699
parent6b907155f7197ebce5f345de2500d0ff3f8bfaab (diff)
downloadjdk-6293299dd341721b33424c7012b1123bb267cabb.tar.gz
jdk-6293299dd341721b33424c7012b1123bb267cabb.zip
8264824: java/net/Inet6Address/B6206527.java doesn't close ServerSocket properly
Reviewed-by: aefimov, dfuchs, michaelm, vtewari
-rw-r--r--test/jdk/java/net/Inet6Address/B6206527.java20
1 files changed, 11 insertions, 9 deletions
diff --git a/test/jdk/java/net/Inet6Address/B6206527.java b/test/jdk/java/net/Inet6Address/B6206527.java
index 6189606be31..e853d828a02 100644
--- a/test/jdk/java/net/Inet6Address/B6206527.java
+++ b/test/jdk/java/net/Inet6Address/B6206527.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -40,22 +40,24 @@ public class B6206527 {
public static void main (String[] args) throws Exception {
Inet6Address addr = getLocalAddr();
if (addr == null) {
- System.out.println ("Could not find a link-local address");
+ System.out.println("Could not find a link-local address");
return;
}
- ServerSocket ss = new ServerSocket();
- System.out.println ("trying LL addr: " + addr);
- ss.bind(new InetSocketAddress(addr, 0));
+ try (ServerSocket ss = new ServerSocket()) {
+ System.out.println("trying LL addr: " + addr);
+ ss.bind(new InetSocketAddress(addr, 0));
+ }
// need to remove the %scope suffix
- addr = (Inet6Address)InetAddress.getByAddress (
+ addr = (Inet6Address) InetAddress.getByAddress (
addr.getAddress()
);
- System.out.println ("trying LL addr: " + addr);
- ss = new ServerSocket();
- ss.bind(new InetSocketAddress(addr, 0));
+ try (ServerSocket ss = new ServerSocket()) {
+ System.out.println("trying LL addr: " + addr);
+ ss.bind(new InetSocketAddress(addr, 0));
+ }
}
public static Inet6Address getLocalAddr() throws Exception {