From 43e901fc4b45c0fe868825f49f56866937210646 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Thu, 15 Aug 2024 21:19:58 +0200 Subject: [PATCH] Improve URL handling --- .../javadoc/AbstractFixJavadocMojo.java | 2 +- .../plugins/javadoc/AbstractJavadocMojo.java | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java index a48d8d099..506aa4ad7 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java @@ -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); } } diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java index 9310370fd..7e62bcc6b 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java @@ -5421,7 +5421,7 @@ private URL getResource(final List 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()); } } @@ -5758,8 +5758,11 @@ private Set followLinks(Set links) { Set 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()); @@ -5768,9 +5771,6 @@ private Set followLinks(Set 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; @@ -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)) { @@ -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;