cancel
Showing results for 
Search instead for 
Did you mean: 

ClassCastException after redeploy of component

Former Member
0 Kudos

We are developing simple component(Iview) , using session and component context beans and one jsp page.

After <u>second</u> deploy(we did not make "clean" or "delete" of previously deployed par) of the par file, we have :

ClassCastException when try to assign bean from component context to local variable:

We have exception in follow code:

XBean myXBean = null;

public void doInitialization() throws PageException {

.....//here error:

myXBean=(XBean)myComponentContext.getValue

("myXBeanName");

....

}

It seems this bean exists in component context , but this is already bean of other type(different Class Loaders?).

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

I had a similar problem with custom beans saved in session. My solution was to logout and login again so that session context linked to previous implementation of the class is lost and recreated with the new one in new deploy.

The other "smarter" option might be to check if "myXBeanName" is instance of your current class implementation... if not just discard it and instanciate a new one.

Object myTempXBean=myComponentContext.getValue

("myXBeanName");

if(myTempXBean instanceof XBean )

{

//cast it and use it

XBean myXBean = (XBean) myTempXBean;

}

else

{

//drop it and instantiate a new one

//because class has changed

}

Give points if this answers your question

Regards

Vitaliano

Former Member
0 Kudos

Thank you for interest.

This code will not work, because instanceof does not pay attention on difference between class loaders.

if(myTempXBean instanceof XBean )

{

//cast it and use it

XBean myXBean = (XBean) myTempXBean;

}

The simplest approach is catch ClassCastException and remove old bean.

But now I try to remove all beans from context in some "destroy" method.

Former Member
0 Kudos

Yes, the problem is either different classloaders or different serialver on the class.

See for a looong discussion on the topic