diff --git a/test/docs/jdk/javadoc/doccheck/checks/jdkCheckLinks.java b/test/docs/jdk/javadoc/doccheck/checks/jdkCheckLinks.java index bd818923d9f..3db1cdf6cb9 100644 --- a/test/docs/jdk/javadoc/doccheck/checks/jdkCheckLinks.java +++ b/test/docs/jdk/javadoc/doccheck/checks/jdkCheckLinks.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 2025, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 8337109 + * @bug 8337109 8349369 * @summary Check Links in the generated documentation * @library /test/langtools/tools/lib ../../doccheck /test/lib ../../../../tools/tester * @build DocTester toolbox.TestRunner diff --git a/test/docs/jdk/javadoc/doccheck/doccheckutils/FileProcessor.java b/test/docs/jdk/javadoc/doccheck/doccheckutils/FileProcessor.java index 6ae3a473bdb..2291d649c3a 100644 --- a/test/docs/jdk/javadoc/doccheck/doccheckutils/FileProcessor.java +++ b/test/docs/jdk/javadoc/doccheck/doccheckutils/FileProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 2025, 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 @@ -44,16 +44,16 @@ public class FileProcessor { public void processFiles(Path directory) { try { - Files.walkFileTree(directory, new SimpleFileVisitor() { + Files.walkFileTree(directory, new SimpleFileVisitor<>() { @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { if (file.toString().endsWith(".html")) files.add(file); return FileVisitResult.CONTINUE; } @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + public FileVisitResult postVisitDirectory(Path dir, IOException exc) { return FileVisitResult.CONTINUE; } }); diff --git a/test/docs/jdk/javadoc/doccheck/doccheckutils/checkers/LinkChecker.java b/test/docs/jdk/javadoc/doccheck/doccheckutils/checkers/LinkChecker.java index 62ead5a25d3..ed0098d2714 100644 --- a/test/docs/jdk/javadoc/doccheck/doccheckutils/checkers/LinkChecker.java +++ b/test/docs/jdk/javadoc/doccheck/doccheckutils/checkers/LinkChecker.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 2025, 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 @@ -220,20 +220,14 @@ public class LinkChecker implements HtmlChecker { @Override public boolean isOK() { - return duplicateIds == 0 - && missingIds == 0 - && missingFiles == 0 - && badSchemes == 0; + return log.noErrors() && (missingFiles == 0); } @Override public void close() { - report(); - if (!isOK()) { - throw new RuntimeException( - "LinkChecker encountered errors. Duplicate IDs: " - + duplicateIds + ", Missing IDs: " + missingIds - + ", Missing Files: " + missingFiles + ", Bad Schemes: " + badSchemes); + if (!log.noErrors()) { + report(); + throw new RuntimeException("LinkChecker encountered errors; see log above."); } } @@ -276,6 +270,11 @@ public class LinkChecker implements HtmlChecker { p = currFile.getParent().resolve(resolvedUriPath).normalize(); } + if (!Files.exists(p)) { + log.log(currFile, line, "missing file reference: " + log.relativize(p)); + return; + } + if (fragment != null && !fragment.isEmpty()) { foundReference(line, p, fragment); } @@ -392,7 +391,7 @@ public class LinkChecker implements HtmlChecker { void addID(int line, String name) { if (checked) { - throw new IllegalStateException("Adding ID after file has been"); + throw new IllegalStateException("Adding ID after file has been checked"); } Objects.requireNonNull(name); IDInfo info = map.computeIfAbsent(name, _ -> new IDInfo()); @@ -413,7 +412,9 @@ public class LinkChecker implements HtmlChecker { if (name != null) { IDInfo id = map.get(name); if (id == null || !id.declared) { - log.log(log.relativize(from), line, "id not found: " + this.pathOrURI + "#" + name); + log.log(log.relativize(from), line, + "id not found: " + this.pathOrURI + "#" + name); + LinkChecker.this.missingIds++; } } } else { @@ -429,7 +430,8 @@ public class LinkChecker implements HtmlChecker { map.forEach((name, id) -> { if (name != null && !id.declared) { for (Position ref : id.references) { - log.log(log.relativize(ref.path), ref.line, "id not found: " + this.pathOrURI + "#" + name); + log.log(log.relativize(ref.path), ref.line, + "id not found: " + this.pathOrURI + "#" + name); } missingIds++; }