3

I am using a log4j 1.2.16 and root logger with EnhancedPatternLayout for my purposes.

The code is something like that (Catching exceptions in a ScheduledFuture):

try
{
    _task.run();
}
catch(RejectedExecutionException ree) {}
catch (Exception e)
{
    log.error("Exception in a scheduled task:", e);
}


And that's what happens next, some kinds of exceptions do not leave any stacktrace in the log file.

Here's a normal log for NPE:

[24.11.12 11:08:31] Exception in a scheduled task:
java.lang.NullPointerException
    at com.test.server.taskmanager.TestTask$1.run(TestTask.java:116)
    at com.test.server.threading.RunnableWrapper.execute(RunnableWrapper.java:65)
    at com.test.server.threading.RunnableWrapper.run(RunnableWrapper.java:57)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
        .....

And next is ClassCastException:

[24.11.12 11:16:37] ...
[24.11.12 11:18:30] Exception in a scheduled task:
java.lang.ClassCastException
[24.11.12 11:18:37] ...
[24.11.12 11:20:37] ...
[24.11.12 11:21:51] Exception in a scheduled task:
java.lang.ClassCastException
[24.11.12 11:22:37] ...


I don't get it .. where is the stacktrace for ClassCastException?
Why this happens and is there any way to fix that?

VirtualVoid
  • 1,005
  • 3
  • 17
  • 25
  • 3
    Could this be your answer? It seems some Exceptions are "Fast Thrown" which can cause this: http://stackoverflow.com/questions/2411487/nullpointerexception-in-java-with-no-stacktrace – Cory Kendall Nov 24 '12 at 09:54
  • Seems it could be very useful. Never knew about this optimization. I'll try tomorrow, thanks Cory. – VirtualVoid Nov 24 '12 at 10:02

0 Answers0