--- old/test/java/io/File/Basic.java 2017-06-14 23:18:01.237572017 -0700 +++ new/test/java/io/File/Basic.java 2017-06-14 23:18:01.019681014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2017, 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 @@ -22,13 +22,13 @@ */ /* @test - @bug 4165666 4203706 4288670 4290024 - @summary Basic heartbeat test for File methods that access the filesystem - - @build Basic Util - @run shell basic.sh + * @bug 4165666 4203706 4288670 4290024 + * @summary Basic heartbeat test for File methods that access the filesystem + * @build Basic Util + * @run main/othervm Basic */ +import java.io.FileOutputStream; import java.io.IOException; import java.io.File; import java.io.PrintStream; @@ -39,13 +39,14 @@ static PrintStream out = System.err; - static File nonExistantFile = new File("x.Basic.non"); static File rwFile = new File("x.Basic.rw"); static File bigFile = new File("x.Basic.big"); static File roFile = new File("x.Basic.ro"); static File thisDir = new File("."); static File dir = new File("x.Basic.dir"); + static File dir2 = new File("x.Basic.dir2"); static File nonDir = new File("x.Basic.nonDir"); + static byte bytes[] = new byte[] {1, 2, 3, 4, 5, 6}; static void showBoolean(String what, boolean value) { out.println(" " + what + ": " + value); @@ -75,7 +76,6 @@ if (!f.canRead()) fail(f, "is not readable"); if (!Util.isPrivileged() && f.canWrite() != writeable) fail(f, writeable ? "is not writeable" : "is writeable"); - int rwLen = 6; if (f.length() != length) fail(f, "has wrong length"); } @@ -83,16 +83,34 @@ throw new Exception(f + " " + why); } - public static void main(String[] args) throws Exception { + static void setup() throws Exception { + rwFile.delete(); + bigFile.delete(); + roFile.delete(); + thisDir.delete(); + dir.delete(); + dir2.delete(); + nonDir.delete(); + + try (FileOutputStream fos = new FileOutputStream(rwFile)) { + fos.write(bytes); + } + + roFile.createNewFile(); + roFile.setReadOnly(); + + dir.mkdir(); + } - show(nonExistantFile); - if (nonExistantFile.exists()) fail(nonExistantFile, "exists"); + public static void main(String[] args) throws Exception { + setup(); show(rwFile); - testFile(rwFile, true, 6); + testFile(rwFile, true, bytes.length); rwFile.delete(); - if (rwFile.exists()) + if (rwFile.exists()) { fail(rwFile, "could not delete"); + } show(roFile); testFile(roFile, false, 0); @@ -106,20 +124,25 @@ String[] fs = thisDir.list(); if (fs == null) fail(thisDir, "list() returned null"); out.print(" [" + fs.length + "]"); - for (int i = 0; i < fs.length; i++) + for (int i = 0; i < fs.length; i++) { out.print(" " + fs[i]); + } out.println(); if (fs.length == 0) fail(thisDir, "is empty"); - if (!nonExistantFile.createNewFile()) - fail(nonExistantFile, "could not create"); - nonExistantFile.deleteOnExit(); - - if (!nonDir.mkdir()) + if (!nonDir.mkdir()) { fail(nonDir, "could not create"); + } + if (!nonDir.exists() || !nonDir.isDirectory()) { + fail(nonDir, "not created"); + } - if (!dir.renameTo(new File("x.Basic.dir2"))) + if (!dir.renameTo(dir2)) { fail(dir, "failed to rename"); + } + if (dir.exists() || !dir2.exists() || !dir2.isDirectory()) { + fail(dir, "not renamed"); + } if (System.getProperty("os.name").equals("SunOS") && System.getProperty("os.version").compareTo("5.6") >= 0) {