# HG changeset patch # User jjiang # Date 1530581261 -28800 # Node ID 14708e1acdc3974f4539027cbbcfa6d69f83cf51 # Parent 1e24c7152e473de808a3803f8869f88ead186c16 8205984: javax/net/ssl/compatibility/Compatibility.java failed to access port log file Summary: Release resource after reading port log file Reviewed-by: xuelei diff -r 1e24c7152e47 -r 14708e1acdc3 test/jdk/javax/net/ssl/compatibility/Compatibility.java --- a/test/jdk/javax/net/ssl/compatibility/Compatibility.java Mon Jul 02 17:54:36 2018 -0700 +++ b/test/jdk/javax/net/ssl/compatibility/Compatibility.java Tue Jul 03 09:27:41 2018 +0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2018, 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 @@ -51,6 +51,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import java.util.stream.Stream; import jdk.test.lib.process.OutputAnalyzer; @@ -157,10 +158,6 @@ "ServerStatus=%s, ClientStatus=%s, CaseStatus=%s%n", serverStatus, clientStatus, testCase.getStatus()); - // Confirm the server has stopped. - if(new File(Utils.PORT_LOG).exists()) { - throw new RuntimeException("Server doesn't stop."); - } System.out.println("----- Case end -----"); } } @@ -236,10 +233,12 @@ private static List jdkList(String listFileProp) throws IOException { String listFile = System.getProperty(listFileProp); System.out.println(listFileProp + "=" + listFile); - if (listFile != null && new File(listFile).exists()) { - return Files.lines(Paths.get(listFile)) - .filter(line -> { return !line.trim().isEmpty(); }) - .collect(Collectors.toList()); + if (listFile != null && Files.exists(Paths.get(listFile))) { + try (Stream lines = Files.lines(Paths.get(listFile))) { + return lines.filter(line -> { + return !line.trim().isEmpty(); + }).collect(Collectors.toList()); + } } else { return new ArrayList<>(); } @@ -263,12 +262,13 @@ // Retrieves the latest server port from port.log. private static int getServerPort() throws IOException { - if (!new File(Utils.PORT_LOG).exists()) { + if (!Files.exists(Paths.get(Utils.PORT_LOG))) { return -1; } - return Integer.valueOf( - Files.lines(Paths.get(Utils.PORT_LOG)).findFirst().get()); + try (Stream lines = Files.lines(Paths.get(Utils.PORT_LOG))) { + return Integer.valueOf(lines.findFirst().get()); + } } private static OutputAnalyzer runServer(String jdkPath, diff -r 1e24c7152e47 -r 14708e1acdc3 test/jdk/javax/net/ssl/compatibility/Server.java --- a/test/jdk/javax/net/ssl/compatibility/Server.java Mon Jul 02 17:54:36 2018 -0700 +++ b/test/jdk/javax/net/ssl/compatibility/Server.java Tue Jul 03 09:27:41 2018 +0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2018, 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 @@ -146,10 +146,9 @@ server.close(); } - // Cleanups port.log. - File file = new File(Utils.PORT_LOG); - if (file.exists()) { - file.delete(); + // Cleanups port log. + if (!new File(Utils.PORT_LOG).delete()) { + throw new RuntimeException("Cannot delete port log"); } }