Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 353192

Summary: Error message when multiple jetty jars are on the classpath is unhelpful
Product: [RT] Jetty Reporter: Geir Hedemark <geir>
Component: serverAssignee: Greg Wilkins <gregw>
Status: RESOLVED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: geir, jetty-inbox
Version: unspecified   
Target Milestone: 7.5.x   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Geir Hedemark CLA 2011-07-27 06:28:54 EDT
Build Identifier: tip of git

Error message is java.lang.IllegalArgumentException: Object is not of type class org.eclipse.jetty.server.Server

The error message should include the actual class found, and the most common error scenario (multiple jetty jars on classpath)

Reproducible: Always
Comment 1 Geir Hedemark CLA 2011-07-27 06:30:24 EDT
Suggested patch:

diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java
index 6ba2729..b92b121 100644
--- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java
+++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java
@@ -307,7 +307,7 @@ public class XmlConfiguration
             // Check the class of the object
             Class<?> oClass = (Class<?>)nodeClass(_config);
             if (oClass != null && !oClass.isInstance(obj))
-                throw new IllegalArgumentException("Object is not of type " + oClass);
+                throw new IllegalArgumentException("Object is not of type " + oClass+". Actual type is "+obj.getClass()+". If names look the same there may be several jetty jar files on the classpath.");
             configure(obj,_config,0);
             return obj;
         }
Comment 2 Greg Wilkins CLA 2011-08-29 00:39:44 EDT
thanks for the suggestion.

I went with:

            if (oClass != null && !oClass.isInstance(obj))
            {
                String loaders = (oClass.getClassLoader()==obj.getClass().getClassLoader())?"":"Object Class and type Class are from different loaders.";
                throw new IllegalArgumentException("Object of class '"+obj.getClass().getCanonicalName()+"' is not of type '" + oClass.getCanonicalName()+"'. "+loaders);
            }