8202708: Add a check of opening stream for not-existing UNC url

Reviewed-by: rriggs
This commit is contained in:
Felix Yang 2018-05-14 11:17:18 -07:00
parent 0d6885f792
commit e02ef02e11

@ -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 @@ import java.net.*;
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 {
URL u = new URL(badHttp);
try {
InputStream in = u.openStream();
} catch (IOException x) {
return;
}
throw new RuntimeException("Expected UnknownHostException to be thrown");
testHttp();
testUnc();
}
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 (UnknownHostException x) {
System.out.println("UnknownHostException is thrown as expected.");
return;
}
throw new RuntimeException("Expected UnknownHostException to be " +
"thrown for " + url);
}
}