Skip to content
New issue

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

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

Already on GitHub? # to your account

Failed to instantiate [java.util.List]: Specified class is an interface #2202

Closed
dkirrane opened this issue Feb 2, 2024 · 2 comments
Closed
Labels
theme: integration An issue or change related to integration with other frameworks, shells or operating systems
Milestone

Comments

@dkirrane
Copy link

dkirrane commented Feb 2, 2024

I'm getting the following warning

2024-02-02 | 10:46:54.394 |  WARN | main | picocli.spring.PicocliSpringFactory | 
Unable to get bean of class interface java.util.List, using fallback factory picocli.CommandLine$DefaultFactory
(org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'java.util.List': Failed to instantiate [java.util.List]: 
Specified class is an interface)

my guess is it's coming from the following but I'm not exactly sure.

    @Option(
            names = "-topics",
            required = true,
            split = ",",
            arity = "1..*",
            description = "List of topic names")
    List<String> topics;

I'm using

        <dependency>
            <groupId>info.picocli</groupId>
            <artifactId>picocli-spring-boot-starter</artifactId>
            <version>4.7.5</version>
        </dependency>
@remkop
Copy link
Owner

remkop commented Feb 2, 2024

Thank you for raising this.

This is strange and should not be happening. I thought I had a test for this but I'll double check. I may need more details or a minimum example to reproduce the issue.

@remkop remkop added the theme: integration An issue or change related to integration with other frameworks, shells or operating systems label Feb 21, 2024
@remkop
Copy link
Owner

remkop commented Feb 21, 2024

Sorry for the late response.

From the code, it looks like there is no problem.
The log simply reports that it was unable to create a Bean java.util.List, and after logging that warning, the call to the default factory succeeds in creating a concrete List instance.

Potential improvements:

  • The log message is confusing; the message should be clearer that while Spring was unable to instantiate a List, the library will now delegate to the Picocli factory and try again. The current message suggests that the Picocli default factory was also unable to instantiate a List, which is misleading.
  • Should the log level be WARN? Multi-value List and Map options will always result in these log messages being generated, so this is not a cause for concern, but business as usual. Perhaps INFO is a more appropriate log level here.

@remkop remkop added this to the 4.7.6 milestone Feb 21, 2024
@remkop remkop closed this as completed in a82062b Apr 9, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
theme: integration An issue or change related to integration with other frameworks, shells or operating systems
Projects
None yet
Development

No branches or pull requests

2 participants