changeset 50654:6f6e8c1b4208

8202708: Add a check of opening stream for not-existing UNC url Reviewed-by: rriggs
author xiaofeya
date Mon, 14 May 2018 11:17:18 -0700
parents 4ea7917929b9
children 24151f48582b
files test/jdk/java/net/URL/OpenStream.java
diffstat 1 files changed, 27 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/java/net/URL/OpenStream.java	Mon May 14 12:03:59 2018 +0100
+++ b/test/jdk/java/net/URL/OpenStream.java	Mon May 14 11:17:18 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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,8 +22,9 @@
  */
 
 /* @test
-   @bug 4064962
-   @summary openStream should work even when not using proxies
+ * @bug 4064962 8202708
+ * @summary openStream should work even when not using proxies and
+ *          UnknownHostException is thrown as expected.
  */
 
 import java.io.*;
@@ -32,18 +33,36 @@
 
 public class OpenStream {
 
-    static String badHttp = "http://foo.bar.baz/";
+    private static final String badHttp = "http://foo.bar.baz/";
+    private static final String badUnc = "file://h7qbp368oix47/not-exist.txt";
 
     public static void main(String[] args) throws IOException {
+        testHttp();
+        testUnc();
+    }
 
-        URL u = new URL(badHttp);
+    static void testHttp() throws IOException {
+        checkThrows(badHttp);
+    }
+
+    static void testUnc() throws IOException {
+        boolean isWindows = System.getProperty("os.name").startsWith("Windows");
+        if (isWindows) {
+            checkThrows(badUnc);
+        }
+    }
+
+    static void checkThrows(String url) throws IOException {
+        URL u = new URL(url);
         try {
             InputStream in = u.openStream();
-        } catch (IOException x) {
+        } catch (UnknownHostException x) {
+            System.out.println("UnknownHostException is thrown as expected.");
             return;
         }
-        throw new RuntimeException("Expected UnknownHostException to be thrown");
+        throw new RuntimeException("Expected UnknownHostException to be " +
+                "thrown for " + url);
 
     }
+}
 
-}