Skip to content

Commit 98161b7

Browse files
SendaoYanPaul Hohensee
authored andcommitted
8334332: TestIOException.java fails if run by root
Reviewed-by: phh Backport-of: 472b935
1 parent 9bf5502 commit 98161b7

File tree

2 files changed

+55
-15
lines changed

2 files changed

+55
-15
lines changed

test/langtools/TEST.ROOT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ useNewOptions=true
2222

2323
# Use --patch-module instead of -Xmodule:
2424
useNewPatchModule=true
25+
26+
# Path to libraries in the topmost test directory. This is needed so @library
27+
# does not need ../../ notation to reach them
28+
external.lib.roots = ../../

test/langtools/jdk/javadoc/doclet/testIOException/TestIOException.java

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,17 +23,28 @@
2323

2424
/*
2525
* @test
26-
* @bug 8164130
26+
* @bug 8164130 8334332
2727
* @summary test IOException handling
28-
* @library ../lib
28+
* @library ../lib /test/lib
2929
* @modules jdk.javadoc/jdk.javadoc.internal.tool
3030
* @build JavadocTester
3131
* @run main TestIOException
3232
*/
3333

3434
import java.io.File;
3535
import java.io.FileWriter;
36+
import java.nio.file.Path;
37+
import java.nio.file.Files;
38+
import java.util.Map;
3639

40+
import jtreg.SkippedException;
41+
42+
/**
43+
* Tests IO Exception handling.
44+
*
45+
* Update: Windows does not permit setting folder to be readonly.
46+
* https://support.microsoft.com/en-us/help/326549/you-cannot-view-or-change-the-read-only-or-the-system-attributes-of-fo
47+
*/
3748
public class TestIOException extends JavadocTester {
3849

3950
public static void main(String... args) throws Exception {
@@ -45,13 +56,13 @@ public static void main(String... args) throws Exception {
4556
void testReadOnlyDirectory() {
4657
File outDir = new File("out1");
4758
if (!outDir.mkdir()) {
48-
throw new Error("Cannot create directory");
59+
throw skip(outDir, "Cannot create directory");
4960
}
5061
if (!outDir.setReadOnly()) {
51-
throw new Error("could not set directory read-only");
62+
throw skip(outDir, "could not set directory read-only");
5263
}
5364
if (outDir.canWrite()) {
54-
throw new Error("directory is writable");
65+
throw skip(outDir, "directory is writable");
5566
}
5667

5768
try {
@@ -69,15 +80,15 @@ void testReadOnlyDirectory() {
6980
void testReadOnlyFile() throws Exception {
7081
File outDir = new File("out2");
7182
if (!outDir.mkdir()) {
72-
throw new Error("Cannot create directory");
83+
throw skip(outDir, "Cannot create directory");
7384
}
7485
File index = new File(outDir, "index.html");
7586
try (FileWriter fw = new FileWriter(index)) { }
7687
if (!index.setReadOnly()) {
77-
throw new Error("could not set index read-only");
88+
throw skip(index, "could not set index read-only");
7889
}
7990
if (index.canWrite()) {
80-
throw new Error("index is writable");
91+
throw skip(index, "index is writable");
8192
}
8293

8394
try {
@@ -109,13 +120,13 @@ void testReadOnlySubdirectory() throws Exception {
109120
File outDir = new File("out3");
110121
File pkgOutDir = new File(outDir, "p");
111122
if (!pkgOutDir.mkdirs()) {
112-
throw new Error("Cannot create directory");
123+
throw skip(pkgOutDir, "Cannot create directory");
113124
}
114125
if (!pkgOutDir.setReadOnly()) {
115-
throw new Error("could not set directory read-only");
126+
throw skip(pkgOutDir, "could not set directory read-only");
116127
}
117128
if (pkgOutDir.canWrite()) {
118-
throw new Error("directory is writable");
129+
throw skip(pkgOutDir, "directory is writable");
119130
}
120131

121132
// run javadoc and check results
@@ -153,13 +164,13 @@ void testReadOnlyDocFilesDir() throws Exception {
153164
File pkgOutDir = new File(outDir, "p");
154165
File docFilesOutDir = new File(pkgOutDir, "doc-files");
155166
if (!docFilesOutDir.mkdirs()) {
156-
throw new Error("Cannot create directory");
167+
throw skip(docFilesOutDir, "Cannot create directory");
157168
}
158169
if (!docFilesOutDir.setReadOnly()) {
159-
throw new Error("could not set directory read-only");
170+
throw skip(docFilesOutDir, "could not set directory read-only");
160171
}
161172
if (docFilesOutDir.canWrite()) {
162-
throw new Error("directory is writable");
173+
throw skip(docFilesOutDir, "directory is writable");
163174
}
164175

165176
try {
@@ -175,5 +186,30 @@ void testReadOnlyDocFilesDir() throws Exception {
175186
docFilesOutDir.setWritable(true);
176187
}
177188
}
189+
190+
private Error skip(File f, String message) {
191+
out.print(System.getProperty("user.name"));
192+
out.println(f + ": " + message);
193+
showAllAttributes(f.toPath());
194+
throw new SkippedException(f + ": " + message);
195+
}
196+
197+
private void showAllAttributes(Path p) {
198+
showAttributes(p, "*");
199+
showAttributes(p, "posix:*");
200+
showAttributes(p, "dos:*");
201+
}
202+
203+
private void showAttributes(Path p, String attributes) {
204+
out.println("Attributes: " + attributes);
205+
try {
206+
Map<String, Object> map = Files.readAttributes(p, attributes);
207+
map.forEach((n, v) -> out.format(" %-10s: %s%n", n, v));
208+
} catch (UnsupportedOperationException e) {
209+
out.println("Attributes not available " + attributes);
210+
} catch (Throwable t) {
211+
out.println("Error accessing attributes " + attributes + ": " + t);
212+
}
213+
}
178214
}
179215

0 commit comments

Comments
 (0)