Environment/version overview

  • Development tool: Intellij IDEA 2019.3.1
  • Spring – the boot: 2.2.2. RELEASE
  • The JDK: 1.8.0 comes with _111
  • Maven: 3.2.5
  • Lombok: 1.18.10

Problem description

A method throws a large number of NullPointException (NPE) exceptions. However, when I look at the code line where the specific NPE occurs, I find that there is no specific stack information, but only the Exception class name is printed. Therefore, it is impossible to find the exact line of code where NPE occurs

why

Content original address

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.

Translate the following

The compiler in the server VM now provides the correct stack backtrace for all “cold” built-in exceptions. To improve performance, the method can be recompiled when such exceptions are thrown several times. After recompilation, the compiler can choose a faster strategy using preallocated exceptions that do not provide a stack trace. To completely disable pre-allocated anomalies, please use the following new logo: – XX: – OmitStackTraceInFastThrow.

The solution

  • The first solution

    Set the JVM startup parameters to shut down the strategy: – XX: – OmitStackTraceInFastThrow

  • Second solution

    Restarting the server, such as a Spring-boot project, directly reboots the application service. The JVM is rebooted when the server is restarted, and the complete stack information will be printed when the same Exception is encountered again, but the specific stack information will not be printed if the same Exception is encountered repeatedly