https://issues.apache.org/bugzilla/show_bug.cgi?id=43867





--- Comment #58 from Aaron Digulla <[EMAIL PROTECTED]>  2008-08-06 12:24:29 PST 
---
Re: Field.get(Object)

Some background info on reflection and static code in a class.

If you use reflection to access the static data of a class (which Tomcat has to
do to clear static references so it can GC the webapp), then calling
Field.get() will initialize a class if a) it hasn't been initialized, yet, b)
if it has been initialized by a different classloader instead of the current
one or c) when the class itself has been GC'd (not with Sun VM with default GC
options but you can activate that).

There are a lot of spurious problems lurking around this "feature"; I once used
it to execute code while the Groovy compiler worked on my class file. It wasn't
nice.

So what can happen is that you need a class for something (i.e. someone imports
it) but you don't actually use it. In this case, the classloader will have
loaded the class but it won't be initialized. That's a standard optimization to
make Java boot faster.

Then, you shutdown. At that stage, Tomcat will look through all loaded classes
(instead of those which are initialized) and call Field.get(). And that
triggers the bug.

Tomcat can't solve this, because there is no way to ask the VM if a class is
initialized or not.

The only solution for this kind of bug is not to use *any* static fields in
code which will be deployed to Tomcat. Especially the Loggers of log4j must not
be static ... and here we run into trouble because we have to mutually
exclusive design goals.

But maybe we can hack our way out of this. Solution 1 would be to install a
listener which deinitializes log4j in such a way that any getLogger() call
would return null or a NOPLogger or something.

Solution 2 would be to create a private final static field which Tomcat will
eventually clear. If that field is cleared (and only Tomcat can do that since
it's private), you know that you're in the Tomcat shutdown cycle (instead of
some misconfiguration error) and you could ignore attempts to log anything
instead of throwing an error.

Solution 1 would depend a bit on Tomcat but it would be reusable for other app
servers. Solution 2 would be independent of the appserver; any appserver who
clears static fields would just work.


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

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

Reply via email to