Mantis - Resin
Viewing Issue Advanced Details
4649 minor always 07-01-11 13:22 07-05-11 09:50
reza  
ferg  
normal  
closed 4.0.19  
fixed  
none    
none 4.0.20  
0004649: Using InjectionPoint effects bean resolution for Producers
Using InjectionPoint incorrectly effects bean resolution for Producers. It appears that Producers with InjectionPoints are given higher priority over Producers without InjectionPoints. In the following example, the BarBean is resolved for injection when FooBean should be resolved:

================================================================================
@WebServlet(urlPatterns = { "/" })
public class TestServlet extends HttpServlet {
  @Inject
  private TestBean bean;

  protected void doGet(HttpServletRequest request,
      HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter writer = response.getWriter();
    
    writer.println(bean.getData());

    writer.close();
  }
}
================================================================================

================================================================================
@Entity
public interface TestBean {
  public String getData();
}
================================================================================

================================================================================
public class FooBean implements TestBean {
  @Override
  public String getData() {
    return "foo";
  }
}
================================================================================

================================================================================
public class BarBean implements TestBean {
  @Override
  public String getData() {
    return "bar";
  }
}
================================================================================

================================================================================
@Qualifier
@Retention(RUNTIME)
@Target({ METHOD, FIELD, PARAMETER, TYPE })
public @interface BarQualifier {
}
================================================================================

================================================================================
public class TestBeanFactory {

  @Produces
  public TestBean getFoo() {
    return new FooBean();
  }

  @Produces
  @BarQualifier
  public TestBean getBar(InjectionPoint injectionPoint) {
    return new BarBean();
  }
}
================================================================================

Injection resolves correctly if both producers have injection points:

================================================================================
public class TestBeanFactory {

  @Produces
  public TestBean getFoo(InjectionPoint injectionPoint) {
    return new FooBean();
  }

  @Produces
  @BarQualifier
  public TestBean getBar(InjectionPoint injectionPoint) {
    return new BarBean();
  }
}
================================================================================

Injection also resolves correctly if neither producers have injection points:

================================================================================
public class TestBeanFactory {

  @Produces
  public TestBean getFoo() {
    return new FooBean();
  }

  @Produces
  @BarQualifier
  public TestBean getBar() {
    return new BarBean();
  }
}
================================================================================

This issue was originally reported by Max Bureck: http://forum.caucho.com/showthread.php?t=27986. [^]

Notes
(0005348)
ferg   
07-05-11 09:50   
ioc/0775