remkop / picocli

Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc.

Home Page:https://picocli.info

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

dkirrane opened this issue · comments

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>

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.

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.