Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/net/www/protocol/file/DirPermissionDenied.java
41159 views
1
/*
2
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 6977851
27
* @summary NPE from FileURLConnection.connect
28
* @library /test/lib
29
* @build DirPermissionDenied jdk.test.lib.process.*
30
* jdk.test.lib.util.FileUtils
31
* @run testng DirPermissionDenied
32
*/
33
34
import java.io.IOException;
35
import java.net.MalformedURLException;
36
import java.net.URL;
37
import java.net.URLConnection;
38
import java.nio.file.Files;
39
import java.nio.file.Path;
40
import java.nio.file.Paths;
41
42
import jdk.test.lib.process.ProcessTools;
43
import jdk.test.lib.util.FileUtils;
44
import org.testng.annotations.AfterTest;
45
import org.testng.annotations.Test;
46
import org.testng.annotations.BeforeTest;
47
public class DirPermissionDenied {
48
private static final Path TEST_DIR = Paths.get(
49
"DirPermissionDeniedDirectory");
50
51
@Test
52
public void doTest() throws MalformedURLException {
53
URL url = new URL(TEST_DIR.toUri().toString());
54
try {
55
URLConnection uc = url.openConnection();
56
uc.connect();
57
} catch (IOException e) {
58
// OK
59
} catch (Exception e) {
60
throw new RuntimeException("Failed " + e);
61
}
62
63
try {
64
URLConnection uc = url.openConnection();
65
uc.getInputStream();
66
} catch (IOException e) {
67
// OK
68
} catch (Exception e) {
69
throw new RuntimeException("Failed " + e);
70
}
71
72
try {
73
URLConnection uc = url.openConnection();
74
uc.getContentLengthLong();
75
} catch (IOException e) {
76
// OK
77
} catch (Exception e) {
78
throw new RuntimeException("Failed " + e);
79
}
80
}
81
82
@BeforeTest
83
public void setup() throws Throwable {
84
// mkdir and chmod "333"
85
Files.createDirectories(TEST_DIR);
86
ProcessTools.executeCommand("chmod", "333", TEST_DIR.toString())
87
.outputTo(System.out)
88
.errorTo(System.out)
89
.shouldHaveExitValue(0);
90
}
91
92
@AfterTest
93
public void tearDown() throws Throwable {
94
// add read permission to ensure the dir removable
95
ProcessTools.executeCommand("chmod", "733", TEST_DIR.toString())
96
.outputTo(System.out)
97
.errorTo(System.out)
98
.shouldHaveExitValue(0);
99
FileUtils.deleteFileIfExistsWithRetry(TEST_DIR);
100
}
101
}
102
103