element cannot be mapped to a null key

Problem Description

Original address 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)

Cause Analysis:

Because when JAVA8 is used to group fields, there is no non-empty judgment for the field, so there will be problems when loading.


solution:

Map<Object, List<BillFeeVO>> feeGroup = feeVOList.stream().collect(Collectors.groupingBy(BillFeeVO::getBizOperator)); //报错代码
Map<Object, List<BillFeeVO>> feeGroup = feeVOList.stream().filter(item->StringUtil.isNotBlank(item.getBizOperator())).collect(Collectors.groupingBy(BillFeeVO::getBizOperator)); // 增加了字段非空过滤

Guess you like

Origin blog.csdn.net/qq_37196265/article/details/128537394