quarkus: @ConfigProperty of List with empty default value fail with error

Describe the bug

Using this:

    @ConfigProperty(name = "items", defaultValue = "")
    List<String> getItems();

Expected behavior Should return an empty list (at least I would expect)

Actual behavior Throw an exception:

java.util.NoSuchElementException: Property config.items not found

To Reproduce

Run the tests in: https://github.com/ia3andy/check-list-config-empty

Environment (please complete the following information):

  • Quarkus version or git rev: 1.3.1.Final

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 16 (15 by maintainers)

Most upvoted comments

@geoand I still believe that’s is an issue, IMO having a Optional<List<String>> is counter intuitive as Collection are already capable of being empty, why would we want to wrap it in an optional?

When you do things from intuition and it fails, I think we should, most of the time, consider it a bug…

Because every config property may or may not be empty, yet not every type has an empty representation. Additionally, this is a natural consequence of the necessary logic to handle empty values consistently.

@dmlloyd I would handle all Optional<…> as we currently do, but I would also make it directly work with types which have an empty representation. This would also be a consistent way to handle empty IMHO.

I’m sorry you feel this way, but do not make the mistake of assuming that intuition is uniform to all, or that it is necessarily correct. After all, intuition tells us that the Earth is flat…

Well, do you want me to create a rocket trying to prove that Optional<List<..>> is an heresy 😂

… Maybe just a warning logs could at least direct users following their intuition to the right solution 😃 (@geoand I am starting a book on warning logs 😂 😇)

@geoand I know you love me right now 😃