question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when YAML Config + List + Constructor-based converter

See original GitHub issue

Describe the bug

I am getting a strange issue with lists in YAML configuration. The following works ok-ish:

@ConfigProperties
public interface BaseConfiguration {
    public Collection<MyListElement> mylist();

    public class MyListElement { 
        public String text;
        public MyListElement(final String text){ this.text = text.toUpperCase(); }
    }
}

Now I want to make sure I retain the order of the elements in mylist, hence I replace Collection by List. If I do so, Arc refuses the MyListElement class at compile time for not having a no-args constructor 🤔

Caused by: java.lang.IllegalArgumentException: Class 'org.acme.BaseConfiguration$MyListElement' which is used as return type of method 'mylist' in class 'org.acme.BaseConfiguration' must be have a no-args constructor
        at io.quarkus.arc.deployment.configproperties.YamlListObjectHandler.validateClass(YamlListObjectHandler.java:160)

Side-note the typo in the message requiring the class must be have a no-args constructor

If I add the constructor, snakeyaml crashes at run-time asking for a single-argument constructor for a synthetic class org.acme.BaseConfiguration$MyListElement_GeneratedListWrapper_mylist

Caused by: Can't construct a java object for tag:yaml.org,2002:org.acme.BaseConfiguration$MyListElement_GeneratedListWrapper_mylist; exception=No single argument constructor found for class org.acme.BaseConfiguration$MyListElement_GeneratedListWrapper_mylist : null
 in 'string', line 1, column 1:
    element,anotherElement
    ^

        at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:335)
...

Expected behavior

Expect List configuration entries to be working the same way as Collection entries.

Actual behavior

List configuration entries crash with using constructor-based converters.

To Reproduce

Reproducer here: https://github.com/someth2say/quarkus-issue-list-converter

Configuration

base: 
  mylist: 
    - element
    - anotherElement

Environment (please complete the following information):

Output of uname -a or ver

Linux localhost.localdomain 5.10.22-200.fc33.x86_64 #1 SMP Tue Mar 9 22:05:08 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version “11.0.10” 2021-01-19 OpenJDK Runtime Environment GraalVM CE 20.3.1 (build 11.0.10+8-jvmci-20.3-b09) OpenJDK 64-Bit Server VM GraalVM CE 20.3.1 (build 11.0.10+8-jvmci-20.3-b09, mixed mode, sharing)

GraalVM version (if different from Java)

Quarkus version or git rev

1.12.2.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /home/jordisola/.m2/wrapper/dists/apache-maven-3.6.3-bin/1iopthnavndlasol9gbrbg6bf2/apache-maven-3.6.3 Java version: 11.0.10, vendor: GraalVM Community, runtime: /home/jordisola/.sdkman/candidates/java/20.3.1.r11-grl Default locale: en_GB, platform encoding: UTF-8 OS name: “linux”, version: “5.10.22-200.fc33.x86_64”, arch: “amd64”, family: “unix”

Additional context

(Add any other context about the problem here.) https://quarkusio.zulipchat.com/#narrow/stream/187030-users/topic/Errors.20with.20YAML.20config.20.2B.20List.20.20.2B.20Constructor-based.20conve.2E.2E.2E

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
radcortezcommented, Mar 17, 2021

So we plan to replace the @ConfigPropeties interfaces implementation with the one from SR Config, so in the end they should work the same.

0reactions
someth2saycommented, Mar 18, 2021

Sure! The ConfigMapping approach worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix Errors in YAML (.YML) Config Files - Knowledgebase
We have a video tutorial on fixing YAML (.yml) configuration errors: ... Below is a list of common mistakes that people make when...
Read more >
Spring Boot YAML configuration for a list of strings
I have yet to find a way to parse a YAML array in a @Value annotated bean property. – Zirzirikos. Mar 13, 2019...
Read more >
Allow @ConfigurationProperties binding for immutable POJOs
The first step is to get the binder working with our existing mutable configuration property beans. We'll then look at extending the support....
Read more >
no primary or single unique constructor found for class java ...
quarkusio/quarkusError when YAML Config + List + Constructor-based converter# ... List configuration entries crash with using constructor-based converters.
Read more >
Property Binding in Spring Boot 2.0
For .properties and .yaml files, we have written custom loaders that track origins as ... Here's how the failure analyzer shows the error:....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found