诡异的java.lang.ArithmeticException: null

诡异的java.lang.ArithmeticException: null

线上突然出现接口异常,日志信息如下:

13:48:34.968 [http-nio-8701-exec-10] ERROR c.w.k.c.e.GlobalExceptionHandler - 未知异常:
java.lang.ArithmeticException: null
13:49:18.257 [http-nio-8701-exec-3] ERROR c.w.k.c.e.GlobalExceptionHandler - 未知异常:
java.lang.ArithmeticException: null
14:05:40.817 [http-nio-8701-exec-8] ERROR c.w.k.c.e.GlobalExceptionHandler - 未知异常:
java.lang.ArithmeticException: null
14:43:45.592 [http-nio-8701-exec-6] ERROR c.w.k.c.e.GlobalExceptionHandler - 未知异常:
java.lang.ArithmeticException: null

代码中有一块逻辑,是一堆复杂的计算,但是遇到除以零的情况下,整体数据为0

public static BigDecimal divideZeroCheck(Supplier<BigDecimal> a) {
        try {
            return a.get();
        } catch (ArithmeticException e) {
            String message = e.getMessage();
            if (Objects.equals(message, "Division by zero") || Objects.equals(message, "/ by zero")) {
                return BigDecimal.ZERO;
            }
            throw e;
        }
    }

后面了解到,当这种异常出现过多的情况下,异常会被直接优化掉,导致message直接为null

参考这篇文章

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值