Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0003863 [Resin] minor always 01-28-10 09:19 02-10-10 17:12
Reporter ferg View Status public  
Assigned To ferg
Priority normal Resolution fixed  
Status closed   Product Version 4.0.2
Summary 0003863: @Singleton injection
Description (rep by Wesley Wu)

When a @ApplicationScoped/@Singleton bean is designed to be initialized
after webapp starts (I.E. when first http request was fired) instead of being
initialized during startup stage, in given circumstance, it won't be
injected correctly.

This is my test case:

========== StartBean ===========
public class StartBean {
    @Inject
    FirstBean firstBean;
}
========== FirstBean ===========
public class FirstBean {
    @Inject
    SecondBean secondBean;
}
========== SecondBean ===========
public class SecondBean {
    @Inject
    ThirdBean thirdBean;
    @Inject
    FourthBean fourthBean;
}
========== ThirdBean ===========
public class ThirdBean {
    @Inject
    SingletonBean singletonBean;
}
========== FourthBean ===========
public class FourthBean {
    @Inject
    SingletonBean dao;
}
========== SingletonBean ===========
@Singleton
//@Startup
public class SingletonBean {
}
========== MyServlet ===========
public class MyServlet extends HttpServlet {
    @Inject
    StartBean startBean;

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        System.out.println("hello");
    }
}

========= web.xml ===========
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" [^]
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" [^]
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee [^]
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" [^]
           version="2.5">

    <servlet id="MyServlet">
        <servlet-name>MyServlet</servlet-name>
        <servlet-class>com.mycompany.servlet.MyServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/MyServlet</url-pattern>
    </servlet-mapping>
</web-app>

=================================

The "http://localhost:8080/MyServlet" [^] request will produce this exception:

com.mycompany.servlet.MyServlet.startBean:
com.mycompany.beans.StartBean.firstBean:
com.mycompany.beans.FirstBean.secondBean:
com.mycompany.beans.SecondBean.fourthBean:
com.mycompany.beans.FourthBean.singletonBean:
java.lang.IllegalArgumentException:
Can not set com.mycompany.beans.SingletonBean field
com.mycompany.beans.FourthBean.singletonBean
to com.mycompany.beans.FourthBean

When I annotate the SingletonBean as @Startup, it's fine. (uncomment
the //@Startup line in SingletonBean.java)

Either @Singleton or @ApplicationScoped throws the exception.

It's a weird bug, taking me nearly two days to reproduce it in such a
simple test case.
Additional Information
Attached Files

- Relationships

- Notes
(0004425)
ferg
02-10-10 17:12

ioc/0150
 

- Issue History
Date Modified Username Field Change
01-28-10 09:19 ferg New Issue
01-28-10 09:20 ferg Project Quercus => Resin
02-10-10 17:12 ferg Note Added: 0004425
02-10-10 17:12 ferg Assigned To  => ferg
02-10-10 17:12 ferg Status new => closed
02-10-10 17:12 ferg Resolution open => fixed
02-10-10 17:12 ferg Fixed in Version  => 4.0.4


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
28 total queries executed.
25 unique queries executed.
Powered by Mantis Bugtracker