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

GraalVM native image build with mixinStandardHelpOptions is missing a reflect-config entry #2106

Closed
itzg opened this issue Sep 3, 2023 · 4 comments
Assignees
Labels
theme: codegen An issue or change related to the picocli-codegen module type: bug 🐛
Milestone

Comments

@itzg
Copy link

itzg commented Sep 3, 2023

I am experiencing a similar outcome as #850 ; however, my scenario must be unrelated since that issue was resolved.

I am building a "native image" with GraalVM 17.0.8+9-LTS-jvmci-23.0-b14. Executing the application with no arguments results in the exception shown below. Dependencies in gradle build are

    def picocliVersion = '4.7.5'
    implementation "info.picocli:picocli:${picocliVersion}"
    annotationProcessor "info.picocli:picocli-codegen:${picocliVersion}"

I have created a project that reproduces the issue and this Github actions build shows the execution failure.

It seems to be a very particular combination of declarations. I have a sub-command where

  1. its @Command declares mixinStandardHelpOptions = true
  2. the command class has two or more @Option fields

If I comment out the mixinStandardHelpOptions = true or the second option, then the built executable runs fine.

Upon further investigation, I found that the build with failing executable is missing the following entry in the generated reflect-config.json:

  {
    "name" : "picocli.CommandLine$AutoHelpMixin",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "fields" : [
      { "name" : "helpRequested" },
      { "name" : "versionRequested" }
    ]
  }

Failure exception

Exception in thread "main" picocli.CommandLine$InitializationException: picocli.CommandLine$AutoHelpMixin@39308[11](https://github.com/itzg/try-picocli-graalvm-mixinstdhelp/actions/runs/6066310058/job/16456756746#step:5:12)e is not a command: it has no @Command, @Option, @Parameters or @Unmatched annotations
	at picocli.CommandLine$Model$CommandReflection.validateCommandSpec(CommandLine.java:[12](https://github.com/itzg/try-picocli-graalvm-mixinstdhelp/actions/runs/6066310058/job/16456756746#step:5:13)023)
	at picocli.CommandLine$Model$CommandReflection.extractCommandSpec(CommandLine.java:11853)
	at picocli.CommandLine$Model$CommandSpec.forAnnotatedObject(CommandLine.java:6388)
	at picocli.CommandLine$Model$CommandSpec.mixinStandardHelpOptions(CommandLine.java:7385)
	at picocli.CommandLine$Model$CommandReflection.extractCommandSpec(CommandLine.java:11848)
	at picocli.CommandLine$Model$CommandSpec.forAnnotatedObject(CommandLine.java:6388)
	at picocli.CommandLine.<init>(CommandLine.java:230)
	at picocli.CommandLine.toCommandLine(CommandLine.java:3631)
	at picocli.CommandLine.access$16700(CommandLine.java:[14](https://github.com/itzg/try-picocli-graalvm-mixinstdhelp/actions/runs/6066310058/job/16456756746#step:5:15)8)
	at picocli.CommandLine$Model$CommandReflection.initSubcommands(CommandLine.java:1[18](https://github.com/itzg/try-picocli-graalvm-mixinstdhelp/actions/runs/6066310058/job/16456756746#step:5:19)78)
	at picocli.CommandLine$Model$CommandReflection.extractCommandSpec(CommandLine.java:11844)
	at picocli.CommandLine$Model$CommandSpec.forAnnotatedObject(CommandLine.java:6388)
	at picocli.CommandLine.<init>(CommandLine.java:230)
	at picocli.CommandLine.<init>(CommandLine.java:224)
	at picocli.CommandLine.<init>(CommandLine.java:[19](https://github.com/itzg/try-picocli-graalvm-mixinstdhelp/actions/runs/6066310058/job/16456756746#step:5:20)9)
	at app.Application.main(Application.java:14)

reflect-config.json when it doesn't work

[
  {
    "name" : "app.Application",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "fields" : [
      { "name" : "showHelp" }
    ]
  },
  {
    "name" : "app.WithMixinStdHelpCommand",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "fields" : [
      { "name" : "project" },
      { "name" : "version" }
    ]
  }
]

reflect-config.json when it works

[
  {
    "name" : "app.Application",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "fields" : [
      { "name" : "showHelp" }
    ]
  },
  {
    "name" : "app.WithMixinStdHelpCommand",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "fields" : [
      { "name" : "project" }
    ]
  },
  {
    "name" : "picocli.CommandLine$AutoHelpMixin",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "fields" : [
      { "name" : "helpRequested" },
      { "name" : "versionRequested" }
    ]
  }
]
@mfuerstenau
Copy link

mfuerstenau commented Sep 11, 2023

Can confirm. I have no subcommand defined but I encounter this issue in Windows and Linux. Maven 3.8.4, picocli 4.7.5. Main class entry is present but Mixin class entry is missing. Manually adding it fixed the issue.

@itzg You wrote "when it works", did it on occasion work for you?

@remkop remkop added this to the 4.7.6 milestone Sep 11, 2023
@remkop remkop added type: bug 🐛 theme: codegen An issue or change related to the picocli-codegen module labels Sep 11, 2023
@remkop remkop self-assigned this Sep 11, 2023
@remkop
Copy link
Owner

remkop commented Sep 11, 2023

Can confirm. I have no subcommand defined but I encounter this issue in Windows and Linux. Maven 3.8.4, picocli 4.7.5. Main class entry is present but Mixin class entry is missing. Manually adding it fixed the issue.

@itzg You wrote "when it works", did it on occasion work for you?

Thank you both for raising this!

@mfuerstenau you mentioned that you are able to reproduce the issue in a top-level command without subcommands; can you provide more details to help me reproduce the issue? (How many options, does the command have positional parameters, other mixins, ...)

@itzg
Copy link
Author

itzg commented Sep 11, 2023

@itzg You wrote "when it works", did it on occasion work for you?

@mfuerstenau I just meant when there is only one option field declared then the mixin class got auto-discovered and captured in the reflect json. When there were two options, it didn't.

@itzg
Copy link
Author

itzg commented Oct 15, 2023

I found what is causing my issue: the second option in my command class is named "version", which overlaps with the standard help options. At this point the mixin is not added to the outer ComandSpec:

https://github.com/remkop/picocli/blob/6dfd688da3001d5dd865f42288e58dfe32b82765/src/main/java/picocli/CommandLine.java#L7387-L7393

This now seems a self-inflicted issue, so I'm good with closing this issue if it seems like outcome matches expectations.

@remkop remkop closed this as completed Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: codegen An issue or change related to the picocli-codegen module type: bug 🐛
Projects
None yet
Development

No branches or pull requests

3 participants