--- java/org/apache/catalina/deploy/NamingResources.java (revision 1434910) +++ java/org/apache/catalina/deploy/NamingResources.java (working copy) @@ -1190,7 +1190,7 @@ // No match - ignore this injection target continue; } - targetType = convertPrimitiveType(targetType); + targetType = Introspection.convertPrimitiveType(targetType); if (typeClass == null) { // Need to find a common type amongst the injection targets @@ -1243,26 +1243,4 @@ } return null; } - - private Class convertPrimitiveType(Class clazz) { - if (clazz.equals(char.class)) { - return Character.class; - } else if (clazz.equals(int.class)) { - return Integer.class; - } else if (clazz.equals(boolean.class)) { - return Boolean.class; - } else if (clazz.equals(double.class)) { - return Double.class; - } else if (clazz.equals(byte.class)) { - return Byte.class; - } else if (clazz.equals(short.class)) { - return Short.class; - } else if (clazz.equals(long.class)) { - return Long.class; - } else if (clazz.equals(float.class)) { - return Float.class; - } else { - return clazz; - } - } } --- java/org/apache/catalina/startup/WebAnnotationSet.java (revision 1434910) +++ java/org/apache/catalina/startup/WebAnnotationSet.java (working copy) @@ -265,7 +265,7 @@ Resource annotation = field.getAnnotation(Resource.class); String defaultName = classClass.getName() + SEPARATOR + field.getName(); - String defaultType = field.getType().getCanonicalName(); + Class defaultType = field.getType(); addResource(context, annotation, defaultName, defaultType); } } @@ -290,8 +290,8 @@ String defaultName = classClass.getName() + SEPARATOR + Introspection.getPropertyName(method); - String defaultType = - (method.getParameterTypes()[0]).getCanonicalName(); + Class defaultType = + (method.getParameterTypes()[0]); addResource(context, annotation, defaultName, defaultType); } } @@ -309,7 +309,7 @@ } protected static void addResource(Context context, Resource annotation, - String defaultName, String defaultType) { + String defaultName, Class defaultType) { String name = getName(annotation, defaultName); String type = getType(annotation, defaultType); @@ -412,14 +412,14 @@ } - private static String getType(Resource annotation, String defaultType) { - String type = annotation.type().getCanonicalName(); - if (type == null || type.equals("java.lang.Object")) { + private static String getType(Resource annotation, Class defaultType) { + Class type = annotation.type(); + if (type == null || type.equals(Object.class)) { if (defaultType != null) { type = defaultType; } } - return type; + return Introspection.convertPrimitiveType(type).getCanonicalName(); } --- java/org/apache/catalina/util/Introspection.java (revision 1434910) +++ java/org/apache/catalina/util/Introspection.java (working copy) @@ -153,4 +153,34 @@ } return clazz; } + + /** + * Converts the primitive type to its corresponding wrapper. + * + * @param clazz + * Class that will be evaluated + * @return if the parameter is a primitive type returns its wrapper; + * otherwise returns the same class + */ + public static Class convertPrimitiveType(Class clazz) { + if (clazz.equals(char.class)) { + return Character.class; + } else if (clazz.equals(int.class)) { + return Integer.class; + } else if (clazz.equals(boolean.class)) { + return Boolean.class; + } else if (clazz.equals(double.class)) { + return Double.class; + } else if (clazz.equals(byte.class)) { + return Byte.class; + } else if (clazz.equals(short.class)) { + return Short.class; + } else if (clazz.equals(long.class)) { + return Long.class; + } else if (clazz.equals(float.class)) { + return Float.class; + } else { + return clazz; + } + } } --- test/org/apache/catalina/startup/TestContextConfig.java (revision 1434910) +++ test/org/apache/catalina/startup/TestContextConfig.java (working copy) @@ -126,6 +126,25 @@ assertPageContains("/test/testServlet", "postConstruct1()"); } + @Test + public void testBug54448() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + File appDir = new File("test/webapp-3.0-fragments"); + Context context = tomcat.addWebapp(null, "/test", + appDir.getAbsolutePath()); + + Tomcat.addServlet(context, "TestServlet", + "org.apache.catalina.startup.TesterServletWithAnnotations"); + context.addServletMapping("/testServlet", "TestServlet"); + + tomcat.enableNaming(); + + tomcat.start(); + + assertPageContains("/test/testServlet", "envEntry: 1"); + } + private static class CustomDefaultServletSCI implements ServletContainerInitializer { --- test/org/apache/catalina/startup/TesterServletWithAnnotations.java (revision 0) +++ test/org/apache/catalina/startup/TesterServletWithAnnotations.java (working copy) @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.startup; + +import java.io.IOException; + +import javax.annotation.Resource; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class TesterServletWithAnnotations extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Resource(mappedName = "1") + private int envEntry; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + resp.setContentType("text/plain"); + resp.getWriter().print("envEntry: " + envEntry); + } +} +native