Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ARC interferes with Smallrye ConfigProducer #28309

Closed
dirkbolte opened this issue Sep 30, 2022 · 13 comments
Closed

ARC interferes with Smallrye ConfigProducer #28309

dirkbolte opened this issue Sep 30, 2022 · 13 comments
Assignees
Labels
area/config area/kotlin area/smallrye kind/bug Something isn't working triage/needs-reproducer We are waiting for a reproducer.

Comments

@dirkbolte
Copy link

dirkbolte commented Sep 30, 2022

Describe the bug

Language: Kotlin

I want to inject a config property of a list of custom types:

@Provider
class TestClass {
    @ConfigProperty(name = "property.list")
    private lateinit var typeList: List<MyType>

    @ConfigProperty(name = "property.single")
    private lateinit var singleType: MyType
}

While Smallrye can resolve and fill singleType, it fails on the list. The cause in the stack trace is:

Caused by: java.lang.IllegalArgumentException: SRCFG02005: Type has no raw type class: io.quarkus.arc.impl.WildcardTypeImpl@2d198533
	at io.smallrye.config.inject.ConfigProducerUtil.rawTypeOf(ConfigProducerUtil.java:224)
	at io.smallrye.config.inject.ConfigProducerUtil.resolveConverter(ConfigProducerUtil.java:155)
	at io.smallrye.config.inject.ConfigProducerUtil.resolveConverter(ConfigProducerUtil.java:149)
	at io.smallrye.config.inject.ConfigProducerUtil.resolveConverter(ConfigProducerUtil.java:160)
	at io.smallrye.config.inject.ConfigProducerUtil.resolveConverter(ConfigProducerUtil.java:149)
	at io.smallrye.config.inject.ConfigProducerUtil.convertValues(ConfigProducerUtil.java:106)
	at io.smallrye.config.inject.ConfigProducerUtil.getValue(ConfigProducerUtil.java:76)
	at io.smallrye.config.inject.ConfigProducerUtil.getValue(ConfigProducerUtil.java:58)
	at io.smallrye.config.inject.ConfigProducer.producesListConfigProperty(ConfigProducer.java:136)
	at io.smallrye.config.inject.ConfigProducer_ProducerMethod_producesListConfigProperty_1258131a638f518025054697883e1874162124ce_Bean.create(Unknown Source)
	at io.smallrye.config.inject.ConfigProducer_ProducerMethod_producesListConfigProperty_1258131a638f518025054697883e1874162124ce_Bean.get(Unknown Source)
	at io.smallrye.config.inject.ConfigProducer_ProducerMethod_producesListConfigProperty_1258131a638f518025054697883e1874162124ce_Bean.get(Unknown Source)
	at io.quarkus.arc.impl.CurrentInjectionPointProvider.get(CurrentInjectionPointProvider.java:60)
	... 89 more

From what I see, WildcardTypeImpl provides java.util.List as rawType - should it provide the upper bound of actualTypeArgument?

I tried mitigating it by providing an explizit Converter for List<MyType> but the result is the same.

Screenshot 2022-09-30 at 07 42 58

Expected behavior

Config Converter for generic type of List<T> is used.

Actual behavior

Exception and quarkus fails to start.

java.lang.RuntimeException: java.lang.ExceptionInInitializerError

Caused by: java.lang.ExceptionInInitializerError

Caused by: java.lang.RuntimeException: Failed to start quarkus
	at io.quarkus.runner.ApplicationImpl.<clinit>(Unknown Source)
	... 48 more
Caused by: java.lang.RuntimeException: Error injecting java.util.List<? extends de.test.MyType> de.test.TestClass. typeList
Caused by: java.lang.IllegalArgumentException: SRCFG02005: Type has no raw type class: io.quarkus.arc.impl.WildcardTypeImpl@2d198533
	at io.smallrye.config.inject.ConfigProducerUtil.rawTypeOf(ConfigProducerUtil.java:224)
	at io.smallrye.config.inject.ConfigProducerUtil.resolveConverter(ConfigProducerUtil.java:155)
	at io.smallrye.config.inject.ConfigProducerUtil.resolveConverter(ConfigProducerUtil.java:149)
	at io.smallrye.config.inject.ConfigProducerUtil.resolveConverter(ConfigProducerUtil.java:160)
	at io.smallrye.config.inject.ConfigProducerUtil.resolveConverter(ConfigProducerUtil.java:149)
	at io.smallrye.config.inject.ConfigProducerUtil.convertValues(ConfigProducerUtil.java:106)
	at io.smallrye.config.inject.ConfigProducerUtil.getValue(ConfigProducerUtil.java:76)
	at io.smallrye.config.inject.ConfigProducerUtil.getValue(ConfigProducerUtil.java:58)
	at io.smallrye.config.inject.ConfigProducer.producesListConfigProperty(ConfigProducer.java:136)
	at io.smallrye.config.inject.ConfigProducer_ProducerMethod_producesListConfigProperty_1258131a638f518025054697883e1874162124ce_Bean.create(Unknown Source)
	at io.smallrye.config.inject.ConfigProducer_ProducerMethod_producesListConfigProperty_1258131a638f518025054697883e1874162124ce_Bean.get(Unknown Source)
	at io.smallrye.config.inject.ConfigProducer_ProducerMethod_producesListConfigProperty_1258131a638f518025054697883e1874162124ce_Bean.get(Unknown Source)
	at io.quarkus.arc.impl.CurrentInjectionPointProvider.get(CurrentInjectionPointProvider.java:60)
	... 89 more


How to Reproduce?

  1. Create custom type
  2. Create Type Converter and add is to org.eclipse.microprofile.config.spi.Converter
  3. Create Bean using this type as generic parameter of a list
  4. Start Quarkus (or a QuarkusTest)

Output of uname -a or ver

Darwin mymac.local 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:25:27 PDT 2022; root:xnu-8020.141.5~2/RELEASE_X86_64 x86_64

Output of java -version

openjdk version "11.0.16" 2022-07-19 OpenJDK Runtime Environment Temurin-11.0.16+8 (build 11.0.16+8) OpenJDK 64-Bit Server VM Temurin-11.0.16+8 (build 11.0.16+8, mixed mode)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.12.0.Final

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

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)

Additional information

No response

@dirkbolte dirkbolte added the kind/bug Something isn't working label Sep 30, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Sep 30, 2022

@quarkus-bot quarkus-bot bot added area/arc Issue related to ARC (dependency injection) area/kotlin area/smallrye labels Sep 30, 2022
@dirkbolte
Copy link
Author

FYI: When using @ConfigMapping, I can get it working with solely the MyTypeConverter, so no List Converter:

@ConfigMapping
@StaticInitSafe
interface MyConfig {
    fun single(): MyType
    fun list(): List<MyType>
}

@mkouba
Copy link
Contributor

mkouba commented Sep 30, 2022

I think that the problem is caused by the fact that Kotlin translates List<MyType> to something like java.util.List<? extends MyType>, i.e. Kotlin's List is not java.util.List. And SmallRye Config does not seem to handle this kind of injection point correctly, i.e. it does not handle WildcardType at all.

You can try to replace the List<MyType> with java.util.List<MyType> or even MutableList<MyType> as a workaround.

@mkouba mkouba added area/config and removed area/arc Issue related to ARC (dependency injection) labels Sep 30, 2022
@mkouba
Copy link
Contributor

mkouba commented Sep 30, 2022

CC @radcortez

@dirkbolte
Copy link
Author

java.util.List works. With this, the type smallrye gets is java.util.List<de.test.MyType> . Went with @ConfigMapping for my implementation nevertheless.

Is it in the responsibility of smallrye to handle WildcardType or in the responsibility of WildcardType to act as ParameterizedTypeImpl like a List for this kotlin case? I personally would prefer WildcardType to mimic the behaviour of ParameterizedTypeImpl` - or at least the "raw type" should return a parameterizedType of List instead of the List itself.

@mkouba
Copy link
Contributor

mkouba commented Sep 30, 2022

Is it in the responsibility of smallrye to handle WildcardType or in the responsibility of WildcardType to act as ParameterizedTypeImpl like a List for this kotlin case? I personally would prefer WildcardType to mimic the behaviour of ParameterizedTypeImpl` - or at least the "raw type" should return a parameterizedType of List instead of the List itself.

I believe that it's the responsibility of SmallRye Config because the bytecode contains a wildcard. Note that java.lang.reflect.WildcardType does not even declare the getRawType() method.

@Ladicek
Copy link
Contributor

Ladicek commented Sep 30, 2022

I think it would make sense for SmallRye Config's ConfigProducerUtil.rawTypeOf() to consider an upper bound of a wildcard type as its "raw" type.

@radcortez radcortez self-assigned this Sep 30, 2022
@radcortez
Copy link
Member

I'll have a look.

@geoand
Copy link
Contributor

geoand commented Dec 14, 2022

@radcortez was there any progress on this one?

@radcortez
Copy link
Member

Sorry, not yet. I'll try to have a look this week.

@radcortez
Copy link
Member

I've tried to reproduce the issue, both in SmallRye Config and Quarkus, with no luck. Here are the tests:

@dirkbolte can you provide me your own reproducer? Thanks!

@radcortez radcortez added the triage/needs-reproducer We are waiting for a reproducer. label Dec 14, 2022
@dirkbolte
Copy link
Author

sry, I was sloppy: I don't have the test project preserved and now I can't reproduce it either.

@geoand
Copy link
Contributor

geoand commented Dec 15, 2022

So I'll close this for now. If you do manage to create a reproducer, we can reopen

@geoand geoand closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config area/kotlin area/smallrye kind/bug Something isn't working triage/needs-reproducer We are waiting for a reproducer.
Projects
None yet
Development

No branches or pull requests

5 participants