The main research in this article is the relevant content of log4j not printing exception stack, as follows.
Recently, a phenomenon was found in the error log of the online system:
The code uses log4j to print the system runtime exception stack information. The stack information cannot be seen in the error log, only exception information is available. This is a blow to programmers. If there is no stack information, how can I check for bugs?
[01-15 11:29:26] [ERROR] [org.apache.thrift.server.AbstractNonblockingServer$FrameBuffer:524] Unexpected throwable while invoking!
Later I found out that this is an optimization of jdk. JVM will optimize performance. If an exception is frequently thrown, it will be recompiled and no longer print the exception stack.
It is also relatively simple to solve this problem. If you don't want to check the previous log every time and look at the stack, just add -XX:-OmitStackTraceInFastThrow to the startup parameter, you can disable the optimization and force the exception stack to print. This may cause the log file to be too large, but the log files on the production line before today will be compressed, so it doesn't feel that the problem is not big.
[01-15 16:40:09] [ERROR] [org.apache.thrift.server.AbstractNonblockingServer$FrameBuffer:524] Unexpected throwable while invoking!
java.lang.NullPointerException
at com.iqiyi.ttbrain.recommend.selector.services.FilterService.filter2(FilterService.java:42)
at com.iqiyi.ttbrain.recommend.thrift.IFilterService$Processor$filter2.getResult(IFilterService.java:181)
at com.iqiyi.ttbrain.recommend.thrift.IFilterService$Processor$filter2.getResult(IFilterService.java:166)
at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
at org.apache.thrift.server.AbstractNonblockingServer$FrameBuffer.invoke(AbstractNonblockingServer.java:518)
at org.apache.thrift.server.Invocation.run(Invocation.java:18)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
The above is all about this article about the log4j not printing exception stack. I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!