Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/keytool/CloseFile.java
38853 views
/*1* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 648972126* @summary keytool has not closed several file streams27* @author weijun.wang28* @compile -XDignore.symbol.file CloseFile.java29* @run main CloseFile30*31* This test is only useful on Windows, which fails before the fix and succeeds32* after it. On other platforms, it always passes.33*/3435import java.io.*;3637public class CloseFile {38public static void main(String[] args) throws Exception {39remove("f0", false);40remove("f1", false);41run("-keystore f0 -storepass changeit -keypass changeit -genkeypair -dname CN=Haha");42run("-keystore f0 -storepass changeit -keypass changeit -certreq -file f2");43remove("f2", true);44run("-keystore f0 -storepass changeit -keypass changeit -exportcert -file f2");45remove("f2", true);46run("-keystore f0 -storepass changeit -keypass changeit -exportcert -file f2");47run("-keystore f0 -storepass changeit -keypass changeit -delete -alias mykey");48run("-keystore f0 -storepass changeit -keypass changeit -importcert -file f2 -noprompt");49remove("f2", true);50run("-keystore f0 -storepass changeit -keypass changeit -exportcert -file f2");51run("-printcert -file f2");52remove("f2", true);53remove("f0", true);54run("-keystore f0 -storepass changeit -keypass changeit -genkeypair -dname CN=Haha");55run("-importkeystore -srckeystore f0 -destkeystore f1 -srcstorepass changeit -deststorepass changeit");56remove("f0", true);57remove("f1", true);58}5960static void run(String s) throws Exception {61sun.security.tools.keytool.Main.main((s+" -debug -keyalg rsa").split(" "));62}63static void remove(String filename, boolean check) {64new File(filename).delete();65if (check && new File(filename).exists()) {66throw new RuntimeException("Error deleting " + filename);67}68}69}707172