Please review a fix to a bug in processing of the `sourcepath` javadoc option.
The bug is that when `-sourcepath`/`--source-path` is specified, retrieving a module name does not account for any import statements in `module-info.java`. Originally, I was thinking to propose the following simple fix on the `javac` side: diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java index b25c99d3b06..e046b3d310e 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java @@ -1322,10 +1322,9 @@ public static boolean isModuleInfo(JCCompilationUnit tree) { } public static JCModuleDecl getModule(JCCompilationUnit t) { - if (t.defs.nonEmpty()) { - JCTree def = t.defs.head; - if (def.hasTag(MODULEDEF)) - return (JCModuleDecl) def; + for (var d = t.defs; d.nonEmpty(); d = d.tail) { + if (d.head.hasTag(MODULEDEF)) + return (JCModuleDecl) d.head; } return null; } However, Jan Lahoda (@lahodaj) told me that `JCCompilationUnit` already provides this functionality in a like-named method: @DefinedBy(Api.COMPILER_TREE) public JCModuleDecl getModule() { return getModuleDecl(); } ... public JCModuleDecl getModuleDecl() { for (JCTree tree : defs) { if (tree.hasTag(MODULEDEF)) { return (JCModuleDecl) tree; } } return null; } So the actual fix in this PR is even simpler than my original fix. ------------- Commit messages: - Fix - Test Changes: https://git.openjdk.org/jdk/pull/16312/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=16312&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8317289 Stats: 69 lines in 3 files changed: 56 ins; 10 del; 3 mod Patch: https://git.openjdk.org/jdk/pull/16312.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/16312/head:pull/16312 PR: https://git.openjdk.org/jdk/pull/16312