You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2013/01/17 22:48:35 UTC

[Bug 54448] New: Field of primitive type, annotated with @Resource is not recognized as env entry

https://issues.apache.org/bugzilla/show_bug.cgi?id=54448

            Bug ID: 54448
           Summary: Field of primitive type, annotated with @Resource is
                    not recognized as env entry
           Product: Tomcat 7
           Version: 7.0.35
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: violetagg@apache.org
    Classification: Unclassified

Hi,

I have a servlet with one field of primitive type.
The field is annotated with @Resource.


public class MyServlet extends HttpServlet {

    @Resource(mappedName = "1")
    private int envEntry;

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        ...
    }
}


When I request this servlet I receive the following exception:


SEVERE: Allocate exception for servlet MyServlet
javax.naming.NamingException: Cannot create resource instance
    at
org.apache.naming.factory.ResourceEnvFactory.getObjectInstance(ResourceEnvFactory.java:117)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
    at
org.apache.catalina.core.DefaultInstanceManager.lookupFieldResource(DefaultInstanceManager.java:581)
    at
org.apache.catalina.core.DefaultInstanceManager.processAnnotations(DefaultInstanceManager.java:470)
    at
org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:157)
    at
org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:138)
    at
org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1137)
    at
org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:858)
    at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
    at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)


That's because in the method below the primitive types are not 'converted' to
their corresponding wrappers and this field is interpreted not as env entry but
as resource env ref.
org.apache.catalina.startup.WebAnnotationSet.addResource(Context, Resource, 
String, String)


I'm attaching a patch that solves this issue and a test case.

I'm looking forward to your comments.

Regards
Violeta

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 54448] Field of primitive type, annotated with @Resource is not recognized as env entry

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54448

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
                 OS|                            |All

--- Comment #2 from Mark Thomas <ma...@apache.org> ---
Thanks for the report, patch and test case. The patch has been applied to trunk
and 7.0.x and will be included in 7.0.36 onwards.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 54448] Field of primitive type, annotated with @Resource is not recognized as env entry

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54448

--- Comment #1 from Violeta Georgieva <vi...@apache.org> ---
Created attachment 29865
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=29865&action=edit
patch proposal + test

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org