Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

ClassCastException - ClassLoader issues

Thread view: 
Berlin  Brown - 25 Sep 2006 21:26 GMT
I am working with servlet code on Websphere and when I take code off
the 'servletContext', I keep getting a ClassCastException.  They should
be identical and even print outs show the same name.

But when I extract the object off the servletContext, I get a
classCastException.  From reading online, I might have to change the
classloader policy within the server?

Error caused here:

IJythonUtilPlugin plugin = (JythonUtilPlugin)
context.getAttribute(JythonUtilPlugin.PLUGIN_NAME_KEY);

Here is the code I am trying to use to fix the issue.

        log.info("=========================================");
        Object obj = context.getAttribute(JythonUtilPlugin.PLUGIN_NAME_KEY);
        log.info("Current Object Type=" + obj.getClass().getName());
        log.info("Instance Of=" + (obj instanceof JythonUtilPlugin));
        log.info("Class=" + (obj.getClass()));
        String tmp1 = "ClassLoader=" + (obj.getClass().getClassLoader());
        log.info(tmp1.substring(0, 20));
        log.info("This=" + (this.getClass().getClassLoader()));

        // More ClassLoader Checks (from IBM thinkworks)
        java.lang.ClassLoader ctxCl =
Thread.currentThread().getContextClassLoader();
        java.lang.ClassLoader tcCl = JythonUtilPlugin.class.getClassLoader();

        java.lang.ClassLoader soCl = obj.getClass().getClassLoader();
        tmp1 = "ctxCl=" + ((ctxCl == null) ? "null" : ctxCl.toString());
        log.info(tmp1.substring(0, 40));
        tmp1 = "targetCl=" + ((tcCl  == null) ? "null" : tcCl.toString());
        log.info(tmp1.substring(0, 40));
        tmp1 = "sourceCl=" + ((soCl  == null) ? "null" : soCl.toString());
        log.info(tmp1.substring(0, 40));
        log.info("=========================================");
        // End of Classloader Check
Berlin  Brown - 25 Sep 2006 22:45 GMT
> I am working with servlet code on Websphere and when I take code off
> the 'servletContext', I keep getting a ClassCastException.  They should
[quoted text clipped - 34 lines]
>         log.info("=========================================");
>         // End of Classloader Check

Actually, this may be the fix I need. It gives another exception, but
interesting code, otherwise.

    Class clJy1 =
this.getClass().getClassLoader().loadClass("org.spirit.util.JythonUtilPlugin");
        Method m = clJy1.getMethod("getInterpreter", null);
        log.info("Method: " + m);
        PythonInterpreter interp = (PythonInterpreter) m.invoke(objJyPlugin,
new Class[]{});


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.