7

Got an web application running on Tomcat. I log exceptions and their stack traces using slf4j/logback. e.g.

2017-08-01 00:00:00.000 [http-nio-80-exec-5] ERROR g.s.GuiceyRequestFactoryServlet - 'Server Failure'
java.lang.reflect.InvocationTargetException: null
...
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.33]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_131]
Caused by: ...
    ... 59 common frames omitted
Caused by: ...
    ... 64 common frames omitted
java.lang.NullPointerException: null

Because the real place that caused the NPE is nested a few level down within at least two reflection invocations, not sure if thats the case, Tomcat/slf4j/logback does not show the full stacktrace and stopped at the NPE, not further down.

I am expecting something like e.g.

2017-08-01 00:00:00.000 [http-nio-80-exec-5] ERROR g.s.GuiceyRequestFactoryServlet - 'Server Failure'
java.lang.reflect.InvocationTargetException: null
...
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.33]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_131]
Caused by: ...
    ... 59 common frames omitted
Caused by: ...
    ... 64 common frames omitted
Caused by: java.lang.NullPointerException: null
    at java.util.Calendar.setTime(Calendar.java:1770) ~[na:1.8.0_60]
    ... 80 common frames omitted

i.e. to show a deeper stacktrace in the log. Does anyone know where should I look at and how to achieve that? e.g. Tomcat config? logback config? slf4j methods?

Edit

For those thinking this is a duplication of some other question asking about those "... xx common frames omitted", NO, I do not care these lines. I was asking about the last NPE not being printed AT ALL. Please ready carefully first.

user1589188
  • 5,316
  • 17
  • 67
  • 130
  • Possible duplicate of [How can I see a full log of exceptions in JAVA?](https://stackoverflow.com/questions/12226375/how-can-i-see-a-full-log-of-exceptions-in-java) – TechnoCrat Aug 03 '17 at 06:36
  • @TechnoCrat You got my question wrong. I do not care those omitted lines. I care the last NPE not printed at all. – user1589188 Aug 03 '17 at 06:42
  • I retracted flag. what is NPE ? – TechnoCrat Aug 03 '17 at 09:11
  • Short form for NullPointerException. So when you call invoke, it wraps the real exception within InvocationTargetException. Calling invoke multiple times, the real cause of the exception becomes multiple level down. So the first example it stopped printing the stack trace for the NPE, which I guess because it was too deep? What I hope to see is the second example, where the stack trace for the NPE is also printed. – user1589188 Aug 04 '17 at 00:50

2 Answers2

0

This should be possible using -XX:-OmitStackTraceInFastThrow option.

marcel
  • 377
  • 2
  • 9
-1

The ... 59 more frames ommitted only means that these exceptions were already printed before. In Logback you can restructure stack track to avoid duplicates and print stack lines always in correct order.

Adeel
  • 413
  • 1
  • 7
  • 22