Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 353192 - Error message when multiple jetty jars are on the classpath is unhelpful
Summary: Error message when multiple jetty jars are on the classpath is unhelpful
Status: RESOLVED FIXED
Alias: None
Product: Jetty
Classification: RT
Component: server (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 minor (vote)
Target Milestone: 7.5.x   Edit
Assignee: Greg Wilkins CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-27 06:28 EDT by Geir Hedemark CLA
Modified: 2011-08-29 00:39 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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);
            }