On Fri, 28 Apr 2023 12:45:35 GMT, Jan Lahoda <jlah...@openjdk.org> wrote:

>> Jim Laskey has updated the pull request with a new target base due to a 
>> merge or a rebase. The pull request now contains 14 commits:
>> 
>>  - Merge branch 'master' into 8306112
>>  - PreviewFeatures.isEnabled()
>>  - Clean up isPreview
>>  - Missing exception
>>  - Corrections
>>  - Update VM.java
>>  - Clean up testing
>>  - Update TestJavacTaskScanner.java
>>  - Merge branch 'master' into 8306112
>>  - Clean up
>>  - ... and 4 more: https://git.openjdk.org/jdk/compare/96cdf93b...53a5321d
>
> src/java.base/share/classes/jdk/internal/misc/MainMethodFinder.java line 64:
> 
>> 62: 
>> 63:             for (Method method : refc.getDeclaredMethods()) {
>> 64:                 int argc = method.getParameterCount();
> 
> Nit: unused variable?

Remnant.

> src/java.base/share/classes/jdk/internal/misc/MainMethodFinder.java line 147:
> 
>> 145:             }
>> 146: 
>> 147:             return mainClass.getMethod("main", String[].class);
> 
> Nit: could return `mainMethod` here, correct?

Yes

> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java line 453:
> 
>> 451:         }
>> 452:         if (!SourceVersion.isIdentifier(simplename) || 
>> SourceVersion.isKeyword(simplename)) {
>> 453:             log.error(null, Errors.BadFileName(simplename));
> 
> Suggestion:
> 
>             log.error(tree.pos(), Errors.BadFileName(simplename));

Changing

> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java line 462:
> 
>> 460:         for (JCTree def : tree.defs) {
>> 461:             if (def.hasTag(Tag.PACKAGEDEF)) {
>> 462:                 log.error(null, 
>> Errors.AnonymousMainClassShouldNotHavePackageDeclaration);
> 
> Suggestion:
> 
>                 log.error(def.pos(), 
> Errors.AnonymousMainClassShouldNotHavePackageDeclaration);

Changing

> src/jdk.compiler/share/classes/com/sun/tools/javac/launcher/Main.java line 
> 438:
> 
>> 436:             Class<?> appClass = Class.forName(mainClassName, true, cl);
>> 437:             Method main = MainMethodFinder.findMainMethod(appClass);
>> 438:             if (!PreviewFeatures.isEnabled() && (!isStatic(main) || 
>> !isPublic(main))) {
> 
> It seems one can run a main method without parameters without 
> `--enable-preview` using this codepath. That is presumably not intended.

MainMethodFinder won't return a no arg method is without --enable-preview. The 
local testing here is to specialize the error massages.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13689#discussion_r1180477997
PR Review Comment: https://git.openjdk.org/jdk/pull/13689#discussion_r1180477664
PR Review Comment: https://git.openjdk.org/jdk/pull/13689#discussion_r1180482962
PR Review Comment: https://git.openjdk.org/jdk/pull/13689#discussion_r1180482213
PR Review Comment: https://git.openjdk.org/jdk/pull/13689#discussion_r1180479992

Reply via email to