[Java] 纯文本查看 复制代码
package com.cdfive.learn.guava;
import com.google.common.base.Throwables;
/**
* 堆栈信息丢失测试
* -XX:-OmitStackTraceInFastThrow
* @author five
* @date 2018-05-27
*/
public class ThrowablesTest {
public static void main(String[] args) {
int max = 100;
// int max = 10000;// jvm参数增加-XX:-OmitStackTraceInFastThrow,否则只输出java.lang.NullPointerException,没有堆栈信息
for (int i = 1; i <= max; i++) {
try {
npeMethod();
} catch (NullPointerException e) {
if (i == max) {
System.out.println(Throwables.getStackTraceAsString(e));
}
}
}
}
public static void npeMethod() {
String s = null;
s = s.substring(0);
}
}