RFR: JDK-8328339: Static import prevents source launcher from finding class with main method [v2]
Jan Lahoda
jlahoda at openjdk.org
Mon Mar 18 17:43:30 UTC 2024
On Mon, 18 Mar 2024 17:12:38 GMT, Christian Stein <cstein at openjdk.org> wrote:
>> Please review this fix for finding the program class in case the first top-level type has no main method and the order of type compilation does not match the order in the source file - for example by a static import statement being present.
>>
>> Here's an excerpt from [JEP 458](https://openjdk.org/jeps/458#Launch-time-semantics-and-operation)'s "Launch-time semantics and operation" section describing the process:
>>> 5. Determine the launch class of the initial .java file. If the first top level class in the initial file declares a standard main method (`public static void main(String[])` or other standard main entry points as defined in [JEP 463](https://openjdk.org/jeps/463#A-flexible-launch-protocol)), then that class is the launch class. Otherwise, if another top level class in the initial file declares a standard main method and has same name as the file, that class is the launch class. Otherwise, there is no launch class, and the launcher reports an error and stops.
>
> Christian Stein has updated the pull request incrementally with one additional commit since the last revision:
>
> Ensure source-order of declared types in program source file
>
> Move computation of declared types into program descriptor factory.
Overall, looks good to me. Some suggestions for years in the headers + a potential suggestion to re-order gathering the declared types and package name, so that the qualified names can be computed in one step.
src/jdk.compiler/share/classes/com/sun/tools/javac/launcher/MemoryContext.java line 2:
> 1: /*
> 2: * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
Suggestion:
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
src/jdk.compiler/share/classes/com/sun/tools/javac/launcher/ProgramDescriptor.java line 2:
> 1: /*
> 2: * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
Suggestion:
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
src/jdk.compiler/share/classes/com/sun/tools/javac/launcher/ProgramDescriptor.java line 66:
> 64: var task = compiler.getTask(null, standardFileManager, diagnostic -> {}, null, null, units);
> 65: for (var tree : task.parse()) {
> 66: for (var decl : tree.getTypeDecls()) {
Not terribly important, but you could first compute the package name, and then compute the declared types. That would permit creating the fully qualified `declaredTypeNames` in one step, rather than putting the simple names into a List and then going through them again to qualify them.
src/jdk.compiler/share/classes/com/sun/tools/javac/launcher/SourceLauncher.java line 2:
> 1: /*
> 2: * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
Suggestion:
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
-------------
PR Review: https://git.openjdk.org/jdk/pull/18345#pullrequestreview-1943765732
PR Review Comment: https://git.openjdk.org/jdk/pull/18345#discussion_r1528988234
PR Review Comment: https://git.openjdk.org/jdk/pull/18345#discussion_r1528988646
PR Review Comment: https://git.openjdk.org/jdk/pull/18345#discussion_r1528995167
PR Review Comment: https://git.openjdk.org/jdk/pull/18345#discussion_r1528990277
More information about the compiler-dev
mailing list