There's a few unintentional discrepencies in the various VMs with respect to
reflection. I've e.g. seen the InvocationTargetTxception if I reflect with
an anonymous class as opposed to an explicitly defined inner class.

BTW, unless Foo is a Singleton, the static log field will be assigned for
each invocation of the constructor. A side-effect (unless Foo is final) is
that you reassign it when a sub-class of foo is created as well (that is if
the constructor assigning 'log' is called by this sub-class constructor).
This is probably NOT your intention.

I use a similar technique, but I let the category reference be an instance
variable. More memory consumption, but less side-effect prone.

--

Thomas


| -----Original Message-----
| From: Craig Newlander [mailto:[EMAIL PROTECTED]]
| Sent: 22 August 2001 15:55
| To: LOG4J Users Mailing List
| Subject: Log4j and servlets - Reflection Error
|
|
| Strange error here.
| In my Servlet class (foo) I defined a static field member as
|
| private static Category log;
|
| and in its Constructor is
| log = Category.getRoot();
| I can now log until the cows come home.
|
| Now then, I have another class (foobar) which is instantiated via
| reflection
| by foo from foo's service() method
|
| foobar has a static field member as
| private static Category log;
| and in its Constructor is
| log = Category.getInstance(  this.getClass().getName() );
|
| and when foo tries to reflect foobar I recevied a
| java.lang.reflect.InvocationTargetException:
| java.lang.NoClassDefFoundError:
| org/apache/log4j/Category
| foobar never gets instantiated foo keeps chugging along and logs without a
| hitch?
|
| if I remove the log = from foobars construtor foobar can be reflected just
| fine.
|
| Any ideas?
|
|
|
|
|
| ---------------------------------------------------------------------
| To unsubscribe, e-mail: [EMAIL PROTECTED]
| For additional commands, e-mail: [EMAIL PROTECTED]
|
|



*************************************************************************
Copyright ERA Technology Ltd. 2001. (www.era.co.uk). All rights reserved. 
Confidential. No liability whatsoever is accepted for any loss or damage 
suffered as a result of accessing this message or any attachments.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to