Skip to content

Micronaut mixes up a qualified bean from unqualified one when @Replace is used #10506

Description

@RonBarkan

Expected Behavior

When a factory provides a qualified bean and an unqualified bean, Micronaut can't resolve the qualified one.

Example:

@Factory
@Prototype
public class MyFactory {

  @Named("blah")
  @Prototype
  CountDownLatch blah() {
    return new CountDownLatch(1);
  }

  @Singleton
  @Replaces(CountDownLatch.class)
  CountDownLatch foo() {
    return new CountDownLatch(1);
  }
}

@Prototype
public class MyClass {

  @Inject
  public MyClass(@Named("blah") CountDownLatch latch) { }
}

Note there's a Micronaut provided @Factory, which is why @Replaces is used:

@Factory
public class MicronautFactory {
  @Bean
  CountDownLatch foo() {
    return new CountDownLatch(7);  //  7 is really bad for my app :-)
  }
}

This should work but does not.

Actual Behaviour

Even though @Replaces is not qualified, it eliminates the qualified bean, so this code will not run and complain:
No bean of type [java.util.concurrent.CountDownLatch] exists for the given qualifier: @Named('blah')

Same thing with a qualifier annotation.

Steps To Reproduce

See above code snippet.

Environment Information

JDK 21 / Linux

Example Application

No response

Version

3.10.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions