全局異常 element cannot be mapped to a null key >>>>>>>>>>>>>>:
2019-12-24 10:29:10.363 [tms: d6e158839dd7ea27][http-nio-8008-exec-8] ERROR com.runlion.sat.tools.handler.ExceptionHandler - >>>>>>>>> 全局異常 element cannot be mapped to a null key >>>>>>>>>>>>>>
java.lang.NullPointerException: element cannot be mapped to a null key
at java.util.Objects.requireNonNull(Objects.java:228)
at java.util.stream.Collectors.lambda$groupingBy$45(Collectors.java:907)
at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at com.runlion.sat.tms.service.impl.BillFeeServiceImpl.listTotalFee(BillFeeServiceImpl.java:269)
代碼:
Map<Object, List<BillFeeVO>> feeGroup = feeVOList.stream()
.collect(Collectors.groupingBy(BillFeeVO::getBizOperator));
//按照BizOperator分組,此時BizOperator有空值,就會報錯。
// 改爲,增加非空過濾。
Map<Object, List<BillFeeVO>> feeGroup = feeVOList.stream().filter(item->StringUtil.isNotBlank(item.getBizOperator()))
.collect(Collectors.groupingBy(BillFeeVO::getBizOperator));