views:

1084

answers:

2

At one of our customer installations we had thousands of occurrences of the same exception. After a lot of well logged stacktraces (9332) the occurrence of the exception is still logged, but without stacktrace. After restarting the java process, the same thing: This time we had 17858 stacktraces and then only the exception occurrence itself.

There is a similar question here, but no answer...

Is it a log4j feature or bug? (I believe in the former, because I really like, what those apache guys do)

Any ideas?

+1  A: 

Sounds like a feature to me, at least if the stack traces really are identical. Why would you want to make your logs bigger (and thus harder to search) without getting any more information? Will check for configurability of this feature...

EDIT: I've had a look through the log4j code and there's no trace of it. This would strongly suggest that Robert's answer is correct. Nice VM feature IMO :)

Jon Skeet
Thanks for the answer. I don't want to make my log files big (and I like the feature - even if it is a bug...). Problem was, that I first saw those log entries without stack trace (and didn't even think there could be others) which was not very helpful when I tried to find the bug inside my code.
Kai
+13  A: 

Using Java 5 or better?

Then you're seeing:

The compiler in the server VM now provides correct stack backtraces for all "cold" built-in exceptions. For performance purposes, when such an exception is thrown a few times, the method may be recompiled. After recompilation, the compiler may choose a faster tactic using preallocated exceptions that do not provide a stack trace. To disable completely the use of preallocated exceptions, use this new flag: -XX:-OmitStackTraceInFastThrow

Courtesy of the Java 5 release notes.

Robert Munteanu
Thanks. That sounds like the right answer and I will double-check that and then accept this as the right one.
Kai