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

Unsatisfied dependencies for type Boolean with qualifiers @ConfigProperty #9453

Open
charleech opened this issue Nov 1, 2024 · 2 comments
Open

Comments

@charleech
Copy link

Environment Details

  • Helidon Version: 4.1.3
  • Helidon MP
  • JDK version: Temurin-21.0.4+7
  • OS: Windows 11
  • Docker version (if applicable): N/A

Problem Description

I am using Helidon version 4.1.3 with MicroProfile Config and encountered an unusual exception when injecting org.eclipse.microprofile.config.inject.ConfigProperty with jakarta.inject.Provider<Boolean>. The error message states:

org.jboss.weld.exceptions.UnsatisfiedResolutionException: 
    WELD-001334: Unsatisfied dependencies for type Boolean with qualifiers @ConfigProperty 
        at org.jboss.weld.bean.builtin.InstanceImpl.checkBeanResolved(InstanceImpl.java:251)
        at org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:113)
        at it.test.com.my.WalkthroughIT.whenGetConfigFromProvider(WalkthroughIT.java:88)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:38)
        at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:106)
        at it.test.com.my.WalkthroughIT$Proxy$_$$_WeldClientProxy.whenGetConfigFromProvider(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at java.base/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)

Steps to reproduce

Below is my test class:

package it.test.com.my;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import io.helidon.microprofile.testing.junit5.HelidonTest;
import jakarta.inject.Inject;
import jakarta.inject.Provider;

@HelidonTest
class WalkthroughIT {

    @Inject
    @ConfigProperty(
        name = "providerBoolean", defaultValue = "true"
    )
    private Provider<Boolean> providerBoolean;

    @Test
    @DisplayName(
        "When getting config from provider, it must succeed."
    )
    void whenGetConfigFromProvider() {
        BDDAssertions.then(this.providerBoolean).isNotNull();
        BDDAssertions.then(this.providerBoolean.get()).isTrue(); // <--- Exception thrown here.
    }

}

NOTE

Surprisingly, when there is an additional injection of org.eclipse.microprofile.config.inject.ConfigProperty directly with Boolean, no exception occurs.

package it.test.com.my;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import io.helidon.microprofile.testing.junit5.HelidonTest;
import jakarta.inject.Inject;
import jakarta.inject.Provider;

@HelidonTest
class WalkthroughIT {

    @Inject
    @ConfigProperty(
        name = "providerBoolean", defaultValue = "true"
    )
    private Provider<Boolean> providerBoolean;

    @Inject
    @ConfigProperty(
        name = "objectBoolean", defaultValue = "true"
    )
    private Boolean objectBoolean; // <--- Here is an additional.

    @Test
    @DisplayName(
        "When getting config from provider, it must succeed."
    )
    void whenGetConfigFromProvider() {
        BDDAssertions.then(this.providerBoolean).isNotNull();
        BDDAssertions.then(this.providerBoolean.get()).isTrue(); // <--- This works like a charm.
    }

}

Could you please provide further advice? Thank you very much for your help in advance. I look forward to hearing from you soon.

@charleech
Copy link
Author

This failure, along with the workaround, also applies to the injection of ConfigProperty with the following (and possibly others):

  • Provider<Byte>
  • Provider<Long>
  • Provider<Float>
  • Provider<Double>
  • Provider<Character>
  • Provider<String>

@charleech
Copy link
Author

Additionally, the custom Converter is also affected, and the workaround is also successful.

package it.test.com.my;

import java.util.concurrent.TimeUnit;
import org.eclipse.microprofile.config.spi.Converter;

public class TimeUnitConverter implements Converter<TimeUnit> {

    @Override
    public TimeUnit convert(final String value)
                    throws IllegalArgumentException,
                           NullPointerException {

        return TimeUnit.valueOf(value);

    }

}
# META-INF/services/org.eclipse.microprofile.config.spi.Converter

it.test.com.my.TimeUnitConverter
package it.test.com.my;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import io.helidon.microprofile.testing.junit5.HelidonTest;
import jakarta.inject.Inject;
import jakarta.inject.Provider;

@HelidonTest
class WalkthroughIT {

    @Inject
    @ConfigProperty(
        name = "providerTimeUnit", defaultValue = "MILLISECONDS"
    )
    private Provider<TimeUnit> providerTimeUnit;

    @Inject
    @ConfigProperty(
        name = "objectTimeUnit", defaultValue = "SECONDS"
    )
    private TimeUnit objectTimeUnit; // <--- Here is an additional.
                                     // <--- Without it, an exception is thrown.

    @Test
    @DisplayName(
        "When getting config from provider, it must succeed."
    )
    void whenGetConfigFromProvider() {
        BDDAssertions.then(this.providerTimeUnit).isNotNull();
        BDDAssertions.then(this.providerTimeUnit.get()).
            isEqualTo(TimeUnit.MILLISECONDS); // <--- This works like a charm.
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Triage
Development

No branches or pull requests

1 participant