java.time包的一次踩坑,报错仅 clock/month/temporal 等文案问题。
事情起因是线上接口出现报错 { "code" : 1, "msg" : "temporal", "data" : null } 当时就懵逼过去。我们一般的异常都有断言去处理。这个报错意味着 e.getMessage() 仅仅是个 temporal 再修改报错返回发布之后获得了完整报错信息。 LocalDate. from (temporal); // LocalDate 源码 public static LocalDate from (TemporalAccessor temporal) { Objects. requireNonNull (temporal , "temporal" ) ; LocalDate date = temporal.query(TemporalQueries. localDate ()) ; if (date == null ) { throw new DateTimeException( "Unable to obtain LocalDate from TemporalAccessor: " + temporal + " of type " + temporal.getClass().getName()) ; } return date ; } 这报错倒是简单了。但是碰到的人就懵逼了。java.time 包的都是这种写法。 对比下其他类的源码 //