Author: markt
Date: Wed Sep 21 13:57:21 2016
New Revision: 1761740

URL: http://svn.apache.org/viewvc?rev=1761740&view=rev
Log:
Review of https://bz.apache.org/bugzilla/show_bug.cgi?id=60151
Improve the exception error messages when a ResourceLink fails to specify the 
type, specifies an unknown type or specifies the wrong type.

Added:
    tomcat/trunk/java/org/apache/naming/factory/LocalStrings.properties   (with 
props)
Modified:
    tomcat/trunk/java/org/apache/naming/factory/ResourceLinkFactory.java
    tomcat/trunk/webapps/docs/changelog.xml

Added: tomcat/trunk/java/org/apache/naming/factory/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/factory/LocalStrings.properties?rev=1761740&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/naming/factory/LocalStrings.properties (added)
+++ tomcat/trunk/java/org/apache/naming/factory/LocalStrings.properties Wed Sep 
21 13:57:21 2016
@@ -0,0 +1,18 @@
+# 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.
+
+resourceLinkFactory.nullType=The local resource link [{0}] that refers to 
global resource [{1}] does not specify the required attribute type
+resourceLinkFactory.unknownType=The local resource link [{0}] that refers to 
global resource [{1}] specified the unknown type [{2}]
+resourceLinkFactory.wrongType=The local resource link [{0}] that refers to 
global resource [{1}] was expected to return an instance of [{2}] but returned 
an instance of [{3}]
\ No newline at end of file

Propchange: tomcat/trunk/java/org/apache/naming/factory/LocalStrings.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/java/org/apache/naming/factory/ResourceLinkFactory.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/factory/ResourceLinkFactory.java?rev=1761740&r1=1761739&r2=1761740&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/naming/factory/ResourceLinkFactory.java 
(original)
+++ tomcat/trunk/java/org/apache/naming/factory/ResourceLinkFactory.java Wed 
Sep 21 13:57:21 2016
@@ -29,6 +29,7 @@ import javax.naming.Reference;
 import javax.naming.spi.ObjectFactory;
 
 import org.apache.naming.ResourceLinkRef;
+import org.apache.naming.StringManager;
 
 /**
  * <p>Object factory for resource links.</p>
@@ -39,6 +40,8 @@ public class ResourceLinkFactory impleme
 
     // ------------------------------------------------------- Static Variables
 
+    private static final StringManager sm = 
StringManager.getManager(ResourceLinkFactory.class);
+
     /**
      * Global naming context.
      */
@@ -146,14 +149,20 @@ public class ResourceLinkFactory impleme
             result = globalContext.lookup(globalName);
             // Check the expected type
             String expectedClassName = ref.getClassName();
+            if (expectedClassName == null) {
+                throw new IllegalArgumentException(
+                        sm.getString("resourceLinkFactory.nullType", name, 
globalName));
+            }
             try {
                 Class<?> expectedClazz = Class.forName(
                         expectedClassName, true, 
Thread.currentThread().getContextClassLoader());
                 if (!expectedClazz.isAssignableFrom(result.getClass())) {
-                    throw new IllegalArgumentException();
+                    throw new 
IllegalArgumentException(sm.getString("resourceLinkFactory.wrongType",
+                            name, globalName, expectedClassName, 
result.getClass().getName()));
                 }
             } catch (ClassNotFoundException e) {
-                throw new IllegalStateException(e);
+                throw new 
IllegalArgumentException(sm.getString("resourceLinkFactory.unknownType",
+                        name, globalName, expectedClassName), e);
             }
             return result;
         }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1761740&r1=1761739&r2=1761740&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed Sep 21 13:57:21 2016
@@ -84,6 +84,11 @@
         calls to WebResource.getInputStream() trigger caching if the resource 
is
         small enough. Patch provided by mohitchugh. (markt)
       </fix>
+      <add>
+        <bug>60151</bug>: Improve the exception error messages when a
+        <code>ResourceLink</code> fails to specify the type, specifies an
+        unknown type or specifies the wrong type. (markt)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Coyote">



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

Reply via email to