Bookmark Topic Watch Topic
  • New Topic

ClassLoader problem :ClassCastException

 
Peter Kovgan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi all!
Please help me resolve the problem:
When I make JNDI lookup to get reference to some server object :
SomeClass mbs = (SomeClass) initCtx.lookup("some");
I receive ClassCastException, I know my server use different class loader to load this object.
Somebody knows how to make casting when classes loaded by different class loaders?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
So you are finding that the following code reports the same Class but different ClassLoaders?

If this is the problem you are having, there is a very nasty fix where you get a PipedStream with ObjectStreams at either end. You get your instance as an Object, pass it through the piped Stream and then do the cast at the other end. I don't have sample code available, but I can go look if you want.
Dave.
 
Peter Kovgan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please!!! Give me example!!!
Please!!!
 
Peter Kovgan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Report post to moderator
I tried to do somthing, but have a new problem: lookupED object does not Serializable, then ObjectOutputStream oos = new ObjectOutputStream(obj); does not work, can you send me another example?

If we passed through streams, the reference to remote object still avaiable?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
OK, I found it.
I really do have to say 'Use this at your own risk'. We should probably start to look at your setuo and find out why you are having ClassLoader problems. I consider the following piece of code a horrible hack that is designed to hide problems, not fix them.

If we passed through streams, the reference to remote object still avaiable?
Yes and No. The new object loses the reference, but you still have access to the old object. You'll need to decide what to do about that if you need call-backs. You might need to create a proxy that wraps the problem class and passes method calls via reflection...
I hope this gets you started though.
Dave
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't post the same question in multiple forums, it creates duplicate conversations and annoys the people trying to help you.
Anyone who wants to contribute should see this thread.
Dave
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
I hereby close this topic.
 
    Bookmark Topic Watch Topic
  • New Topic