The casting itself isn't the problem.  The issue is the ClassLoader.   When
jasper tries to pick up classes off tomcat's classpath dynamically issues
popup.

        For example.
                        You can be working on a JSP file.   Hit it from the browser.  
It
compiles, everything is fine.   Now.   You want to import a file that is in
your WEB-INF/classes directory.    So you do a <%@page import="">  and try
Cast an extisting object (one that was in the previously compile page) to
the type you just imported.   Most likely you will get a ClassCastException
even though it is an instanceof what your trying to cast to.

        You can regenerate this error on Win32.   I haven't tried it on Unix.  But
I wouldn't be suprised if this didn't happen at all on Unix.

        Over all.  Tomcat just needs to support better ClassLoading support on
Win32.  Which I am pretty sure is a development environment for most of us.

-----Original Message-----
From: Warren Crossing [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 29, 2001 5:19 PM
To: '[EMAIL PROTECTED]'
Subject: RE: Wierd Casting Problem. Tomocat Bug?


Hi,

I have experienced the same problem, in varying degrees of complexity..
I think it may be possible to trick java using Serialization & the
serialVersionUID field in a class.
the tool serialver displays the serialVersionUID of a class and this use of
serialization is typically used in streaming objects across physical,
logical & persistence boundaries..

Really sketchy answer i know.. but may be worth looking into..

Someone must know something about safe casting?

Wozza.


-----Original Message-----
From: Ivan [mailto:[EMAIL PROTECTED]]
Sent: Monday, 30 April 2001 5:10 AM
To: [EMAIL PROTECTED]
Subject: Re: Wierd Casting Problem. Tomocat Bug?


I posted the same problem yesterday but totally solved it on my case

two things

Technically Java should only allow you to cast an object to a superclass or
subclass of the class, so if member is not inherited from Object then trying
to cast an object to a member should fail.  however i found this rule not
enforced.

What i found was that i was rebuilding as i tested without restarting the
server and thus the object in the vector had a diffrenent time stamp than
the class i just rebuilt which is why the instanceof test failed even
thought it returned the exaxt class name i was testing for.

Therefore, make sure to restart your server after you rebuild your code or
else the types wont match since the old class signature may already be
loaded.

Hope this helps,
Ivan

PS my problem is fixed know so i dont think it is a tomcat bug

----- Original Message -----
From: "Cory L Hubert" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, April 29, 2001 11:13 AM
Subject: RE: Wierd Casting Problem. Tomocat Bug?


> I found out the problem.  This looks like an extreme hack though.
>
> <$=((member) ((Object)e.nextElement()) ).getFname()%>
>
> Works.   But why do I have to cast to an Object before I cast it back to
> it's appropiate type.   My only guess is that the Servlet DownCast the
> Vector to an Object (because there is some reflection that goes on) before
> setting the Attribute and passing it to JSP.
> But the actual member objects are put in the Vector as member Objects.
> Any Ideas?  Does anyone thing it's wierd that you have to cast to and
Object
> then to the Type.
> I believe this isn't a Java Bug it may be a Tomcat Bug.  Because I don't
> have to cast to an Object, if I am casting to member objects in the
Servlet.
>
>
> -----Original Message-----
> From: Cory L Hubert [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, April 29, 2001 3:46 AM
> To: [EMAIL PROTECTED]
> Subject: Wierd Casting Problem.
>
>
> Ok.  Here is the problem.  I am using Model 2 Architecture.  So my Servlet
> handles all the biz logic and pushes the results that are then displayed
by
> jsp pages.
>
> Within a jsp page I grab my vector from the request like so..
>
> Vector mems =(Vector)request.getAttribute("response");
>
> Then I try to loop around it and cast it to the appropiate Object. Like
> so...
> <%
> for (int i=0; i < mems.size(); i++) {
>
> member m = (member)mems.get(i);
> %>
> <%=m.getFname()%>
> <%}%>
>
>
> I get a ClassCastException.   But when I do a toString on the Object
> itself without casting, it specifies the package name of the object that I
> am trying to cast to.
>
> To make matters wierder.  When I do a getClass().isInstance(THE OBJECT I
> WANT TO CAST TO) it returns false?
>
> What is going on here?  Is this some classLoader issue?
>
>
> Some tips that might help figure this issue out......
>
> I am importing the class I am casting, in the JSP page. like so..
>
> <%@page import="thepackage.member, java.util.*"%>
>
> And the class itself isn't in a jar.  It's in the WEB-INF/classes
> directory.
>
> I also changed the container from a Vector to an ArrayList and got the
> same results.
>
> And I can instantiate the member object itself and use it in the jsp
> page.
>
> Any ideas?  Please.  Someone, HELP!!!
>

Reply via email to