Hi Michael,

I haven't had any direct experience of the type you describe, but I have a couple of 
thoughts:

1. If you're using Java 1.4, you might be able to examine the stack trace 
programatically, and not call any logging in your toString() if you realise that 
you're already in a logging call.

2. A while ago, I had NPEs calling toString() on some of my objects. How could that 
happen when I hadn't overriden toString()? It took me a long time to track down that 
the fault was that I had a bug in my implementation of hashCode(), which of course is 
called by the default toString() behaviour.

Moral of the story: don't do anything that could cause toString() to fail. toString() 
shouldn't have any side-effects, so I don't really see any need for you to log that it 
was called, that doesn't seem to me to be a less "robust" approach. Of course, 
everyone has different requirements, so that's just my opinion...

Hope this helps
Keith




-----Original Message-----
From: Lutz Michael [mailto:[EMAIL PROTECTED]
Sent: 29 September 2004 20:25
To: 'Log4J Users List'; Agassi Emin; Osaki Thomas (ext); Marano Howard
Subject: recursive stack failure




Has anyone run into the following situation?  If so please share how you
handled it.

Scenario: Objects paced into MDC overload their toString() methods (which
determine log content), but they make logging calls in their toString()
methods themselves resulting in stack recursion failure.  JVM crash & burn.

I'm hoping there's a recommended approach for handling this.  Obviously we
can try to avoid placing logging calls in our toString() methods for objects
placed into MDC, but we wanted to make sure there's not a more robust
approach.

Thanks in advance.

Mike

_______________________________________________
Siemens Medical Solutions Health Services 
Michael Lutz
Software Engineer, Soarian Common Components
51 Valley Stream Parkway, Malvern, PA 19355 
Office / Voice Mail     +01 610-219-8613 
Cell                    +01 610-952-2289
Home Office             +01 610-989-3623
Fax                     +01 610-219-4004 
E-mail <mailto:[EMAIL PROTECTED]> 
_______________________________________________


-------------------------------------------------------------------------------
This message and any included attachments are from Siemens Medical Solutions 
USA, Inc. and are intended only for the addressee(s).  
The information contained herein may include trade secrets or privileged or 
otherwise confidential information.  Unauthorized review, forwarding, printing, 
copying, distributing, or using such information is strictly prohibited and may 
be unlawful.  If you received this message in error, or have reason to believe 
you are not authorized to receive it, please promptly delete this message and 
notify the sender by e-mail with a copy to [EMAIL PROTECTED] 

Thank you

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


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

Reply via email to