Re: Class Cast Exception when using development mode and changing source

2000-07-12 Thread Karl Avedal

Hello Kevin,

Kevin Duffey wrote:

 Hi,

 I am using the development mode (true) and set up the source directory to
 point to my source. When I save a change, and refresh the page, I am always
 getting a Class Cast Exception error. I store a bean called HtmlBean as
 application scope. In the .java generated, I see that the
 syncronized(application) {  } code is where the exception is occuring. It
 looks something like this:

 com.bm.ui.beans.HtmlBean htmlBean;
 synchronized(application)
 {
   htmlBean = (com.bm.ui.beans.HtmlBean)application.getAttribute("htmlBean");
   if(htmlBean == null)
   {
 htmlBean = new com.bm.ui.beans.HtmlBean();
 application.setAttribute("htmlBean", htmlBean);
   }
 }


Note that you're storing the bean as an application scope variable. This means
that the bean scope is tied to lifetime of your web-application, not the
session. In your case, as the class is modified you will still have the "old"
bean stored in the ServletContext and you try to cast it to the "new" bean.
Normally Orion should restart the web-application in such a case and serialize
the application scope contents across the restart (but of course, if your bean
isn't serializable with a serialVersionUID set, the values will be lost between
restarts, as usual).

We will look into if this is due to something wrong in Orion's behaviour or if
it can be something else. Possibly the old application hasn't died and
serialized the application contents.

Regards,
Karl Avedal





RE: Class Cast Exception when using development mode and changing source

2000-07-12 Thread Kevin Duffey

Hi Karl,

You brought to my attention two things that I wasn't doing. First, I didn't
realize this..but the HtmlBean was not implementing the Serializable
interface. I added that.

Second, I notice you say to use something called serialVersionUID, what is
that about? I recall one of our engineers say that all classes implementing
serializable needed a specific UID set, but from what I read, that was not
necessary. He also reimplements the serializable interface in every
descendant class and each one sets this variable to some number. Is his way
correct? Also, if so..how do you get the number?

Thanks.


 Kevin Duffey wrote:

  Hi,
 
  I am using the development mode (true) and set up the source
 directory to
  point to my source. When I save a change, and refresh the page,
 I am always
  getting a Class Cast Exception error. I store a bean called HtmlBean as
  application scope. In the .java generated, I see that the
  syncronized(application) {  } code is where the exception is
 occuring. It
  looks something like this:
 
  com.bm.ui.beans.HtmlBean htmlBean;
  synchronized(application)
  {
htmlBean =
 (com.bm.ui.beans.HtmlBean)application.getAttribute("htmlBean");
if(htmlBean == null)
{
  htmlBean = new com.bm.ui.beans.HtmlBean();
  application.setAttribute("htmlBean", htmlBean);
}
  }
 

 Note that you're storing the bean as an application scope
 variable. This means
 that the bean scope is tied to lifetime of your web-application, not the
 session. In your case, as the class is modified you will still
 have the "old"
 bean stored in the ServletContext and you try to cast it to the
 "new" bean.
 Normally Orion should restart the web-application in such a case
 and serialize
 the application scope contents across the restart (but of course,
 if your bean
 isn't serializable with a serialVersionUID set, the values will
 be lost between
 restarts, as usual).

 We will look into if this is due to something wrong in Orion's
 behaviour or if
 it can be something else. Possibly the old application hasn't died and
 serialized the application contents.

 Regards,
 Karl Avedal







Class Cast Exception when using development mode and changing source

2000-07-11 Thread Kevin Duffey

Hi,

I am using the development mode (true) and set up the source directory to
point to my source. When I save a change, and refresh the page, I am always
getting a Class Cast Exception error. I store a bean called HtmlBean as
application scope. In the .java generated, I see that the
syncronized(application) {  } code is where the exception is occuring. It
looks something like this:

com.bm.ui.beans.HtmlBean htmlBean;
synchronized(application)
{
  htmlBean = (com.bm.ui.beans.HtmlBean)application.getAttribute("htmlBean");
  if(htmlBean == null)
  {
htmlBean = new com.bm.ui.beans.HtmlBean();
application.setAttribute("htmlBean", htmlBean);
  }
}

So, my question now becomes, when in development mode using the
source-reload feature of Orion, does Orion "kill" any HttpSession objects?
Even so, this code should just recreate the bean and store it in the
session. The line that causes the exception is htmlBean =
(com.bm.ui.beans.HtmlBean) application.getAttribute("htmlBean");

One thought comes to mind..can you typecast a null into an object? If the
application.getAttribute("htmlBean") returns null, does that cause the
problem..that its being typecasted to com.bm.ui.beans.HtmlBean)? If so, it
would seem the code should read:  if( application.getAttribute("htmlBean")
== null ) { ..create bean and store it..} else htmlBean =
(com.bm.ui.beans.HtmlBean) application.getAttribute("htmlBean");

Thanks for any help.