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

Method parameter injection fails with parametrized argument types #149

Closed
JHahnHRO opened this issue Dec 4, 2022 · 4 comments · Fixed by #152
Closed

Method parameter injection fails with parametrized argument types #149

JHahnHRO opened this issue Dec 4, 2022 · 4 comments · Fixed by #152

Comments

@JHahnHRO
Copy link
Contributor

JHahnHRO commented Dec 4, 2022

The following three test fail:

@ApplicationScoped
public class MapProducer {

    @Produces
    @Dependent
    public <T> Map<String,T> produceMap(InjectionPoint ip) {
        Map<String, T> map = new HashMap<>();
        map.put(ip.getType().getTypeName(), null);
        return map;
    }
}

@EnableWeld
class TestParameterInjectionWithParametrizedTypes {
   @Test
   public void testparamInjectionWithEvent(Event<String> stringEvent) {
       Assertions.assertNotNull(stringEvent);
   }
   @Test
   public void testparamInjectionWithInstance(Instance<String> stringInstance) {
       Assertions.assertNotNull(stringInstance);
   }
   @Test
   public void testparamInjectionWithOtherParametrizedType(Map<String, Integer> map) {
       Assertions.assertNotNull(map);
       Assertions.assertTrue(map.containsKey("java.util.Map<java.lang.String, java.lang.Integer>"));
   }
}

The reason is that WeldJunit5Extension uses
getContainerFromStore(extensionContext).select(parameterContext.getParameter().getType(), ...
instead of
getContainerFromStore(extensionContext).select(parameterContext.getParameter().getParametrizedType(), ...

JHahnHRO pushed a commit to JHahnHRO/weld-testing that referenced this issue Dec 4, 2022
JHahnHRO pushed a commit to JHahnHRO/weld-testing that referenced this issue Dec 4, 2022
JHahnHRO pushed a commit to JHahnHRO/weld-testing that referenced this issue Dec 4, 2022
@manovotn
Copy link
Collaborator

manovotn commented Dec 5, 2022

Thanks for issue and PR @JHahnHRO!
This is a good find that slipped us, I am surprised it hasn't come up sooner.

We can definitely have this fixed on current main branch but older versions are no longer maintained.

@manovotn
Copy link
Collaborator

manovotn commented Dec 5, 2022

Fixed via #152

@JHahnHRO what version are you using? Is this blocking you on 4.0.0.Final?

@manovotn manovotn closed this as completed Dec 5, 2022
@JHahnHRO
Copy link
Contributor Author

JHahnHRO commented Dec 5, 2022

I'm using 2.0.2 regularly, because we're still using javax.* namespaces at work. We're will be migrating to jakarta.*, Wildfly 27+, Quarkus 3, ... next year I hope and I will push for it. However, it's not guaranteed. For the next few months at least, we're stuck with EE8.
And no, it's not blocking per se. I can work around it by using programmatic injection.

@manovotn
Copy link
Collaborator

manovotn commented Dec 6, 2022

Ok, if it were blocking you in some way, do come back and we can look for a solution. Otherwise, I'd rather keep those old versions dormant :)

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

Successfully merging a pull request may close this issue.

2 participants