Skip to Content
author's profile photo
Former Member

ClassCastException & NullPointerException

Hi,

ich have following problem and need help very urgent:

The senario:

there are a JSPDynPage, a JSP and a JavaBean. The JavaBean represents the data container for storing data, which are shown in JSP. Additional I use JavaBean for storing data temporarily between two calls of same JSPDynpage.

The Problem:

Whith reference to the documention of pdk I reduce the visibility of beans and store them after the first call of DynPage to portalcomponent's profile. One moment later, when I call the same DynPage once again and want to retrieve stored bean from profile, there aren't a bean sometimes. In this case I get the NullPointerException.

Do I extend the visibility of beans and store them to session, I get a similar result at the second call. In this case the beans are in the atrributes of session, but I can't cast them to the class I want cast them. In other words: I get a ClassCastException.

The problem also rise sometimes and I can't figure out why. Any idea?

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • author's profile photo
    Former Member
    May 28, 2004 at 01:02 PM

    The first problem sounds very familiar. I've read somthing in an old document that the J2EE engine kan release object in the profile any time it wants. So unless you only use the bean on the subsequent jsp, don't use the IPortalComponentProfile.

    The problem with class cast exception could be that previous versions of you component is stored in the session. When you deploy a new version , the session isn't cleared, and when you retrieve it it's of has the wrong magic number (java property which is changed at every recompile).

    Try clearing the session in the doInitialization method

    Btw are you using the HttpSession or the IPortalComponentSession ?

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      So it doesn't occur in the doProcessAfterInput or doInitialize ?

      Then you can remove the code from the doProcessBeforeOutput method because of the following:

      1. On first call of component doInitialization will be called first, then doProcessBeforeOutput (bean retrieved in doInitialization)

      2. If there is an event, the first method call will be doProcessAfterInput, then the event method and the doProcessBeforeOutput (bean retrieved in doProcessAfterInput).

      btw. my mind recharges regularly so don't worry

  • author's profile photo
    Former Member
    Jun 11, 2004 at 10:54 AM

    Hi,

    I've checked your source code.

    The exception is raised possibly because of two circumstances:

    The ClassCastException occurs because the application context was released. In such a case, upon a new request, the application classloader is newly created. When a(code) class is loaded by two different classloaders, the resulting two classes are not equal to each other, and objects of class A(loaded by classloader A) cannot be cast to class B(loaded by classloader B), and vice versa, although the code is totally equal. The bean object itself was stored in the componentSession, which is itself a wrapper around the HttpSession. So the classloader of the bean object referenced by the session, and the classloader of the newly created application context differed, and each of them had the bean class loaded by itself.

    The second circumstance was that the beans contained massive amounts of data, and have not been removed from the session in application logic, therefore accumulated in the VM. When the VM free memory gets zero, the application contexts are released in an attempt to keep the system running.

    This way, the system behaves similar to the case when an

    application is redeployed, e.g. a ClassCastException occurs upon the attempt to cast the bean object retrieved from the session to the bean type.

    Add comment
    10|10000 characters needed characters exceeded