Skip to content

Commit

Permalink
Improve URL handling
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-o committed Aug 15, 2024
1 parent cb10f78 commit 43e901f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ private ClassLoader getProjectClassLoader() throws MojoExecutionException {
for (String filename : classPath) {
try {
urls.add(new File(filename).toURI().toURL());
} catch (MalformedURLException e) {
} catch (MalformedURLException | IllegalArgumentException e) {
throw new MojoExecutionException("MalformedURLException: " + e.getMessage(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5421,7 +5421,7 @@ private URL getResource(final List<String> classPath, final String resource) {
for (String filename : classPath) {
try {
urls.add(new File(filename).toURI().toURL());
} catch (MalformedURLException e) {
} catch (MalformedURLException | IllegalArgumentException e) {
getLog().error("MalformedURLException: " + e.getMessage());
}
}
Expand Down Expand Up @@ -5758,8 +5758,11 @@ private Set<String> followLinks(Set<String> links) {
Set<String> redirectLinks = new LinkedHashSet<>(links.size());
for (String link : links) {
try {
redirectLinks.add(JavadocUtil.getRedirectUrl(new URI(link).toURL(), settings)
.toString());
redirectLinks.add(
JavadocUtil.getRedirectUrl(new URL(link), settings).toString());
} catch (MalformedURLException | IllegalArgumentException e) {
// only print in debug, it should have been logged already in warn/error because link isn't valid
getLog().debug("Could not follow " + link + ". Reason: " + e.getMessage());
} catch (IOException e) {
// only print in debug, it should have been logged already in warn/error because link isn't valid
getLog().debug("Could not follow " + link + ". Reason: " + e.getMessage());
Expand All @@ -5768,9 +5771,6 @@ private Set<String> followLinks(Set<String> links) {
// incomplete redirect configuration on the server side.
// This partially restores the previous behaviour before fix for MJAVADOC-427
redirectLinks.add(link);
} catch (URISyntaxException | IllegalArgumentException e) {
// only print in debug, it should have been logged already in warn/error because link isn't valid
getLog().debug("Could not follow " + link + ". Reason: " + e.getMessage());
}
}
return redirectLinks;
Expand Down Expand Up @@ -5818,6 +5818,7 @@ protected boolean isValidJavadocLink(String link, boolean detecting) {
return true;
}
} catch (IOException e) {
// ignore this because it is optional
}

if (JavadocUtil.isValidPackageList(packageListUri.toURL(), settings, validateLinks)) {
Expand All @@ -5835,12 +5836,12 @@ protected boolean isValidJavadocLink(String link, boolean detecting) {
}

return false;
} catch (URISyntaxException e) {
} catch (URISyntaxException | MalformedURLException | IllegalArgumentException e) {
if (getLog().isErrorEnabled()) {
if (detecting) {
getLog().warn("Malformed link: " + e.getInput() + ". Ignored it.");
getLog().warn("Malformed link: " + e.getMessage() + ". Ignored it.");
} else {
getLog().error("Malformed link: " + e.getInput() + ". Ignored it.");
getLog().error("Malformed link: " + e.getMessage() + ". Ignored it.");
}
}
return false;
Expand Down

0 comments on commit 43e901f

Please sign in to comment.