tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Richard Mixon (qwest)" <>
Subject RE: NPE in ActionForm where it is not be possible
Date Wed, 14 Jul 2004 17:42:54 GMT

Wow, had not considered that. I'm going to sort of say this back to be
sure I understand though :)

So if we stop Tomcat then my session, with any stored attributes that
contain an ActionForm, will be "serialized" to persistent storage
(disk). Upon restart the sesson and its attributes are
deserialized(reconstituted so to speak). The CATCH is that for any
included ActionForms, "standard" object initialization does not occur -
either through static initializers or through the constructor. So I can
end up with a NPE when I reference the log instance variable.

OK, that definitely explains the problem. It is only after a restart
that this is occurring - consistently. So, how to fix this.

Ugh! I've got 127 classes that use this construct! The good news is that
the objects that are likely to be persisted to the session tend to be
either ActionForms or a limited number of domain objects - about 50 in
total. They mostly derive from common superclasses so I might get some
help by putting an inner class that wraps the Log type in the
superclass. But, I need access to the actual class name of the instance
so I can initialize the Log object with "objectname.class".

Is there a more elegant way to do this? I know using AOP would offer
some much more elegant solutions, but do not think I'm ready to throw
this at a production system.

Any comments/ideas are welcome. And thanks again to Yoav for helping me
to see the light here.

 - Richard

Shapira, Yoav <> wrote:
> Hi,
> Because Log is not Serializable, you can't put it in the session.  So
> making it transient is fine.  I also saw your reasoning for making it
> dynamic rather than static.
> Tomcat will save and restore your sessions across server restarts by
> default.  That includes session attributes that are Serializable.  If
> the Form was in the session, it will be deserialized: this is not the
> same process as reconstruction.  So if you choose to stick with this
> transient modifier, you will need to check for the log being null
> before
> every time you use it.
> Yoav Shapira
> Millennium Research Informatics
>> -----Original Message-----
>> From: Richard Mixon (qwest) []
>> Sent: Tuesday, July 13, 2004 6:26 PM
>> To: Tomcat Users List
>> Subject: RE: NPE in ActionForm where it is not be possible
>> QM <> wrote:
>>> On Sat, Jul 10, 2004 at 12:31:21PM -0700, Richard Mixon (qwest)
> wrote:
>>>> The "log" variable is initialized when the Action form is
>>>>   instantiated, like so: public class ChartWizardForm extends
>>>>       ActionForm implements { private
>>>> transient Log log = LogFactory.getLog(ChartWizardForm.class);
>>>>       ...
>>>> Obviously I'm missing something pretty basic. Is Tomcat re-using a
>>>> form instance across restarts? I've got pretty much default
>>>> settings in Tomcat:
>>> I notice, you define/initialize the instance variable "log" at its
>>> declaration point.
>>> Humor me: what happens if you initialize "log" in the ctor?
>>> -QM
>> I've had to look at higher priorities for a couple of days :)
>> Thanks for the idea. I changed as follows:
>>    ...
>>    // private transient Log log =
>> LogFactory.getLog(ChartWizardForm.class);
>>    private transient Log log; // Logging instance for this class
>> ...
>>    public ChartWizardForm() {
>>        showInactive = false;
>>        altClassMeasOrder = false;
>>        ...
>>        outputFmt="";
>>        scaleFactor="";
>>        log = LogFactory.getLog(ChartWizardForm.class); // <-- ADDED
>>    ...
>> But, still get the NPE :(
>> I'm defininig the instance variable as transient because Tomcat
>> complains about saving sessions that contain a private instance
>> variable (non-transient) of type Log. I was trying to get my
>> sessions to persist across restarts. Does that suggest anything?
>> Thank you again - Richard
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:
> This e-mail, including any attachments, is a confidential business
> communication, and may contain information that is confidential,
> proprietary and/or privileged.  This e-mail is intended only for the
> individual(s) to whom it is addressed, and may not be saved, copied,
> printed, disclosed or used by anyone else.  If you are not the(an)
> intended recipient, please immediately delete this e-mail from your
> computer system and notify the sender.  Thank you.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message