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

Bean injection fails with repositories that use generics #11592

Open
gnarroway-bullish opened this issue Feb 13, 2025 · 1 comment
Open

Bean injection fails with repositories that use generics #11592

gnarroway-bullish opened this issue Feb 13, 2025 · 1 comment

Comments

@gnarroway-bullish
Copy link

gnarroway-bullish commented Feb 13, 2025

Expected Behavior

Repositories with generics should be able to be injected

Actual Behaviour

From micronaut 4.4.0 onwards, it throws an exception

java.util.NoSuchElementException
	at java.base/java.util.ArrayList$Itr.next(ArrayList.java:970)
	at io.micronaut.context.DefaultBeanContext.lastChanceResolve(DefaultBeanContext.java:3233)
	at io.micronaut.context.DefaultBeanContext.pickOneBean(DefaultBeanContext.java:3197)
	at io.micronaut.context.DefaultBeanContext.findConcreteCandidateNoCache(DefaultBeanContext.java:3153)
	at io.micronaut.context.DefaultBeanContext.findConcreteCandidate(DefaultBeanContext.java:3136)
	at io.micronaut.context.DefaultBeanContext.findBeanDefinitionInternal(DefaultBeanContext.java:762)
	at io.micronaut.context.DefaultBeanContext.resolveMetadata(DefaultBeanContext.java:485)
	at io.micronaut.test.extensions.junit5.MicronautJunit5Extension.lambda$alignMocks$0(MicronautJunit5Extension.java:293)
	at java.base/java.util.Optional.ifPresent(Optional.java:178)

Steps To Reproduce

Reproduction provided at https://github.com/gnarroway-bullish/micronaut-error

  1. Clone the project
  2. Run the tests. they will fail
  3. Change the micronautVersion in gradle.properties to 4.3.0 and re-rerun the tests -- they will pass

It passes for 4.1.0-4.3.0 inclusive
It fails for 4.0.0, and 4.4.0-4.7.5 inclusive

#9751 had a related issue which was fixed for a few versions.

Environment Information

  • JDK 21 zulu
  • OSX

Example Application

https://github.com/gnarroway-bullish/micronaut-error

Version

4.7.5

@glorrian
Copy link
Contributor

glorrian commented Feb 16, 2025

Hi! Thanks for the reproduction, it pretty clean. So I think we got this problem due to this one from #8326. I will try to fix it

UPD: there's problem with incomplete Argument (in the right way it should be like Argument of "AInterface<String K, String V> param" but we got just Argument of "AInterface param") it may be just problem with MicronautJunit5Extension.

So your problem exists, but I can't reproduce it in MK's internal tests. This problem occurs because arguments builder is not working properly somewhere and parses this class with incomplete information, and then this line clears the entire list of candidates for implementation, and the application crashes with an exception.

So I think we need to reproduce this without a test frame and see what happens.

UPD2: MK is working fine during execution. The problem exists only in the test frame.

@Context
@Singleton
public class Test {

    @Inject
    private AInterface<String, String> cacheString;

    @Inject
    private AInterface<Long, Long> cacheLong;

    @PostConstruct
    void test() {
        cacheString.get("lk fg", "vfdv");
        cacheLong.get(32L, 32L);
    }
}

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

No branches or pull requests

2 participants