Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow main() to be synthetic in MainClassFinder #2666

Merged
merged 2 commits into from
Aug 6, 2020
Merged

Allow main() to be synthetic in MainClassFinder #2666

merged 2 commits into from
Aug 6, 2020

Conversation

frost13it
Copy link
Contributor

Kotlin compiler allows main() method to take no arguments:

fun main() {
    println("Hello, World!")
}

Under the hood it creates a synthetic method with a signature that is acceptable by JVM (main(java.lang.String[])):

  public static final void main();
    descriptor: ()V
    flags: (0x0019) ACC_PUBLIC, ACC_STATIC, ACC_FINAL
    Code:
      stack=2, locals=2, args_size=0
         0: ldc           #11                 // String Hello, World!
         2: astore_0
         3: iconst_0
         4: istore_1
         5: getstatic     #17                 // Field java/lang/System.out:Ljava/io/PrintStream;
         8: aload_0
         9: invokevirtual #23                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
        12: return
      LineNumberTable:
        line 2: 0
        line 3: 12

  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: (0x1009) ACC_PUBLIC, ACC_STATIC, ACC_SYNTHETIC
    Code:
      stack=0, locals=1, args_size=1
         0: invokestatic  #9                  // Method main:()V
         3: return

But jib does not recognize such a class as the application's entrypoint.

This PR adds ACC_SYNTHETIC to list of allowed main() access flags.

The HelloWorldKt.class in tests is compiled from the code above with kotlinc-jvm 1.3.72 using default settings.

@googlebot

This comment has been minimized.

@frost13it
Copy link
Contributor Author

@googlebot I signed it!

@googlebot

This comment has been minimized.

Copy link
Member

@chanseokoh chanseokoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This makes sense. Thanks for taking your time to fix this (and the test too 👍).

@chanseokoh chanseokoh added this to the v2.5.0 milestone Aug 6, 2020
@chanseokoh chanseokoh requested a review from a team August 6, 2020 14:27
@chanseokoh
Copy link
Member

chanseokoh commented Aug 6, 2020

@GoogleContainerTools/java-tools-build added CHANGELOG entries.

@chanseokoh chanseokoh merged commit c0445b3 into GoogleContainerTools:master Aug 6, 2020
@chanseokoh
Copy link
Member

@frost13it Jib Gradle 2.5.0 and Jib Maven 2.5.2 have been released with your fix. Thanks for your contribution!

@frost13it
Copy link
Contributor Author

@chanseokoh Thanks for such a quick release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants