On Mon, 23 Oct 2023 15:04:29 GMT, Pavel Rappo <pra...@openjdk.org> wrote:
> 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. This pull request has now been integrated. Changeset: fd332da1 Author: Pavel Rappo <pra...@openjdk.org> URL: https://git.openjdk.org/jdk/commit/fd332da1c8a689e91b7124fc342f02b6e0d3dff5 Stats: 69 lines in 3 files changed: 56 ins; 10 del; 3 mod 8317289: javadoc fails with -sourcepath if module-info.java contains import statements Reviewed-by: jlahoda ------------- PR: https://git.openjdk.org/jdk/pull/16312