RFR: JDK-8315458 Implement JEP 463: Implicitly Declared Classes and Instance Main Method (Second Preview) [v26]

Alan Bateman alanb at openjdk.org
Mon Nov 20 13:53:52 UTC 2023


On Sun, 19 Nov 2023 20:14:10 GMT, Jim Laskey <jlaskey at openjdk.org> wrote:

>> Address changes from JEP 445 to JEP 463.
>> 
>> - Move from a SYNTHETIC unnamed class to a MANDATED implicit class.
>> 
>> - Don't mark class on read.
>> 
>> - Remove reflection and annotation processing related to unnamed classes.
>> 
>> - Simplify main method search.
>
> Jim Laskey has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Additional tests for getMainMethod

src/java.base/share/classes/java/lang/Class.java line 4839:

> 4837:     @PreviewFeature(feature=PreviewFeature.Feature.IMPLICIT_CLASSES)
> 4838:     @CallerSensitive
> 4839:     public Method getMainMethod() {

This is a new addition in the last few days. It's somewhat surprising as the  launch protocol has never really surfaced in the API, there's nothing to identify the main class for example. I'm in two minds on surfacing this but it does make the java launcher code much simpler.

Class.getMethod/getMethods return public methods, the proposed getMainMethod may return a public or non-public method and may walk the class hierarchy. So I'm not sure about the naming, it feels more like a findMainMethod to emphasize the search or just mainMethod.

The javadoc probably needs to be fleshed out a bit more to specify how the main method is found.  It currently says "be declared this class's hierarchy" (typo) but it has to say more and make it clear that it may return a Method with a declared class that may be a superclass.

"(@jls 8.4.2)", I assume that should be "{@jls 8.4.2}".

The return description says "the candidate main method". This begs the question if there are other candidates, how do I find them?

The SM permission check looks right, it has to be the same as getDeclaredMethod.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16461#discussion_r1399233970


More information about the compiler-dev mailing list