Skip to content

Commit 28276ac

Browse files
committed
8355475: UNCTest should use an existing UNC path
Backport-of: e6cea4025b6743538da76f056fa831b02705f423
1 parent a7f1e32 commit 28276ac

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

test/jdk/java/net/URLConnection/UNCTest.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2025, 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
@@ -25,17 +25,46 @@
2525
* @test
2626
* @bug 4401485
2727
* @requires (os.family == "windows")
28+
* @modules java.base/sun.net.www.protocol.file
29+
* @library /test/lib
2830
* @summary Check that URL.openConnection() doesn't open connection to UNC
29-
* @run main UNCTest file://jdk/LOCAL-JAVA/jdk1.4/win/README.txt
3031
*/
3132

33+
import jtreg.SkippedException;
34+
import sun.net.www.protocol.file.FileURLConnection;
35+
36+
import java.io.File;
37+
import java.net.InetAddress;
38+
import java.net.URI;
3239
import java.net.URL;
3340
import java.net.URLConnection;
3441

3542
public class UNCTest {
36-
public static void main(String args[]) throws Exception {
37-
URL url = new URL( args[0] );
43+
public static void main(String[] args) throws Exception {
44+
// Get the "computer name" for this host
45+
String hostName = InetAddress.getLocalHost().getHostName();
46+
47+
// UNC path which always exists with Administrative Shares enabled
48+
String path = "\\\\" + hostName + "\\C$\\Windows";
49+
50+
// Skip test if Administrative Shares is disabled
51+
if (! new File(path).exists()) {
52+
throw new SkippedException("Administrative Shares not enabled");
53+
}
54+
55+
// File URL for the UNC path
56+
URL url = new URI("file://" + hostName + "/C$/Windows").toURL();
57+
58+
// Should open a FileURLConnection for the UNC path
3859
URLConnection conn = url.openConnection();
60+
61+
// Sanity check that the connection is a FileURLConnection
62+
if (! (conn instanceof FileURLConnection)) {
63+
throw new Exception("Expected FileURLConnection, instead got "
64+
+ conn.getClass().getName());
65+
}
66+
67+
// Verify that the connection is not in an already connected state
3968
conn.setRequestProperty( "User-Agent", "Java" );
4069
}
4170
}

0 commit comments

Comments
 (0)