Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit cb295fb

Browse files
Abdul Kolarkunnucoffeys
authored andcommitted
8262899: TestRedirectLinks fails
Backport-of: f17ea9e66b68b987b4c780b4a9f99762b8be403b
1 parent 8714642 commit cb295fb

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Extern.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ private static class Fault extends Exception {
387387
private static final long serialVersionUID = 0;
388388

389389
Fault(String msg, Exception cause) {
390-
super(msg, cause);
390+
super(msg + (cause == null ? "" : " (" + cause + ")"), cause);
391391
}
392392
}
393393

test/langtools/jdk/javadoc/doclet/testLinkOption/TestRedirectLinks.java

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2021, 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
@@ -43,9 +43,12 @@
4343
import java.net.InetSocketAddress;
4444
import java.net.URL;
4545
import java.net.URLConnection;
46+
import java.net.UnknownHostException;
4647
import java.nio.file.Files;
4748
import java.nio.file.Path;
4849
import java.security.KeyStore;
50+
import java.time.Duration;
51+
import java.time.Instant;
4952

5053
import javax.net.ssl.HostnameVerifier;
5154
import javax.net.ssl.HttpsURLConnection;
@@ -84,9 +87,31 @@ public static void main(String... args) throws Exception {
8487
*/
8588
@Test
8689
public void testRedirects() throws Exception {
87-
// first, test to see if access to external URLs is available
90+
// This test relies on access to an external resource, which may or may not be
91+
// reliably available, depending on the host system configuration and other
92+
// networking issues. Therefore, it is disabled by default, unless the system
93+
// property "javadoc.dev" is set "true".
94+
String property = "javadoc.dev";
95+
if (!Boolean.getBoolean(property)) {
96+
out.println("Test case disabled by default; "
97+
+ "set system property \"" + property + "\" to true to enable it.");
98+
return;
99+
}
100+
101+
// test to see if access to external URLs is available, and that the URL uses a redirect
102+
88103
URL testURL = new URL("http://docs.oracle.com/en/java/javase/11/docs/api/element-list");
104+
String testURLHost = testURL.getHost();
105+
try {
106+
InetAddress testAddr = InetAddress.getByName(testURLHost);
107+
out.println("Found " + testURLHost + ": " + testAddr);
108+
} catch (UnknownHostException e) {
109+
out.println("Setup failed (" + testURLHost + " not found); this test skipped");
110+
return;
111+
}
112+
89113
boolean haveRedirectURL = false;
114+
Instant start = Instant.now();
90115
try {
91116
URLConnection conn = testURL.openConnection();
92117
conn.connect();
@@ -107,10 +132,12 @@ public void testRedirects() throws Exception {
107132
}
108133
} catch (Exception e) {
109134
out.println("Exception occurred: " + e);
135+
Instant now = Instant.now();
136+
out.println("Attempt took " + Duration.between(start, now).toSeconds() + " seconds");
110137
}
111138

112139
if (!haveRedirectURL) {
113-
out.println("Setup failed; this test skipped");
140+
out.println("Setup failed (no redirect URL); this test skipped");
114141
return;
115142
}
116143

@@ -119,6 +146,7 @@ public void testRedirects() throws Exception {
119146
javadoc("-d", outRedirect,
120147
"-sourcepath", testSrc,
121148
"-link", apiURL,
149+
"-Xdoclint:none",
122150
"pkg");
123151
checkExit(Exit.OK);
124152
checkOutput("pkg/B.html", true,
@@ -157,16 +185,19 @@ public void testWithServers() throws Exception {
157185
new JavacTask(tb)
158186
.outdir(libModules)
159187
.options("--module-source-path", libSrc.toString(),
160-
"--module", "mA,mB")
188+
"--module", "mA,mB",
189+
"-Xdoclint:none")
161190
.run()
162191
.writeAll();
163192

164193
javadoc("-d", libApi.toString(),
165194
"--module-source-path", libSrc.toString(),
166-
"--module", "mA,mB" );
195+
"--module", "mA,mB",
196+
"-Xdoclint:none" );
167197

168198
// start web servers
169-
InetAddress localHost = InetAddress.getLocalHost();
199+
// use loopback address to avoid any issues if proxy is in use
200+
InetAddress localHost = InetAddress.getLoopbackAddress();
170201
try {
171202
oldServer = HttpServer.create(new InetSocketAddress(localHost, 0), 0);
172203
String oldURL = "http:/" + oldServer.getAddress();
@@ -201,7 +232,8 @@ public void testWithServers() throws Exception {
201232
"--module-source-path", src.toString(),
202233
"--module-path", libModules.toString(),
203234
"-link", "http:/" + oldServer.getAddress(),
204-
"--module", "mC" );
235+
"--module", "mC",
236+
"-Xdoclint:none");
205237

206238
} finally {
207239
HttpsURLConnection.setDefaultHostnameVerifier(prevHostNameVerifier);

0 commit comments

Comments
 (0)