Following the instructions at https://picocli.info/picocli-on-graalvm.html graalvm fails to create a native image of a picocli application if @Option fields are defined in abstract super classes. The reason is that ReflectionConfigGenerator creates a json file where the fields of the super class are listed as fields of the concrete command class. This results in error: Error parsing reflection configuration in picocli.json.
So instead of generating
[
{
"name" : "mypackage.MyCommand1",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"fields" : [
{ "name" : "verbose" }
]
},
{
"name" : "mypackage.MyCommand2",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"fields" : [
{ "name" : "verbose" }
]
}
]
the following should be generated:
[
{
"name" : "mypackage.AbstractCommand",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"fields" : [
{ "name" : "verbose" }
]
},
{
"name" : "mypackage.MyCommand1",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true
},
{
"name" : "mypackage.MyCommand2",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true
}
]
The fix seems trivial by changing
https://github.com/remkop/picocli/blob/4407c0c4701ff830cf978412e3d504bd73e6a98f/picocli-codegen/src/main/java/picocli/codegen/aot/graalvm/ReflectionConfigGenerator.java#L291
to
getOrCreateClass(field.getDeclaringClass()).addField(field.getName());
Thank you for the bug report!
I've pushed a fix to the r3.9.x branch and to master. Can you verify?
(I've started to set up a VM for GraalVM testing on my Windows laptop but it is not ready yet...)
Picocli 3.9.4 with a fix for this issue has been released. Enjoy!