Article View: borland.public.jbuilder.java.language
Article #7215Re: ClassCastException that doesn't make sense
From: John McGrath TeamB
Date: Tue, 03 Jul 2001 16:23
Date: Tue, 03 Jul 2001 16:23
35 lines
2368 bytes
2368 bytes
On Tue, 03 Jul 2001 09:39:30 -0500, Lifeng wrote:
> The obj.getClass().getName() returns the right name with full
> qualified path name. However, obj instanceof NewEnrolleeOTW
> returns false.
>
> It can't be caused by different classes with the same name --
> there is only one package contains class NewEnrolleeOTW in
> the whole project. FYI, this NewEnrolleeOTW is a serilazable
> object that passed from a calling object into an EJB. The
> exception occurred in the EJB.
In addition to the the package name and the class name, the identity of
a class includes the ClassLoader that loaded it. Is it possible that
the object was instantiated using a class from a different ClassLoader
than the code doing the testing? In that case, the object *is* of a
different class. "instanceof" will return false and a cast will fail.
I am not an expert on EJBs, but I do know that EJB containers use
multiple ClassLoader instances to keep code separate.
Try evaluating the following expression in that context:
obj.getClass().getClassLoader() == NewEnrolleeOTW.getClassLoader()
If this evaluates to false, then that is your problem.
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID:
<MPG.15abb6d46a9afe9c98a31d@forums.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!feed2.news.rcn.net!rcn!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!t-online.de!news1.dtag.de!news.stgl.sel.alcatel.de!news.stgl.sel.alcatel.de!dnewsReferences:
<3B414660.789CD256@telocity.com> <3b41572c$1_1@dnews> <u3d8e4hg3.fsf@sds.no> <3b4194be$1_2@dnews> <3B41D922.53A88264@gocentrics.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,9bba90999259f167 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-07-03 09:36:37 PST From: John McGrath [TeamB] <ng-b@JPMcGrath.net> Newsgroups: borland.public.jbuilder.java.language Subject: Re: ClassCastException that doesn't make sense Date: Tue, 3 Jul 2001 12:23:43 -0400 Message-ID: <MPG.15abb6d46a9afe9c98a31d@forums.borland.com> References: <3B414660.789CD256@telocity.com> <3b41572c$1_1@dnews> <u3d8e4hg3.fsf@sds.no> <3b4194be$1_2@dnews> <3B41D922.53A88264@gocentrics.com> X-Newsreader: MicroPlanet Gravity v2.30 NNTP-Posting-Host: 209.92.40.60 X-Trace: dnews 994177423 209.92.40.60 (3 Jul 2001 09:23:43 -0700) Lines: 35 X-Authenticated-User: jpmcgrath Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!feed2.news.rcn.net!rcn!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!t-online.de!news1.dtag.de!news.stgl.sel.alcatel.de!news.stgl.sel.alcatel.de!dnews