I've this code where two lists are compared on the "vendor_id" field and I perform join on them. However this line is throwing NPE. I tried guarding with null
but it doesn't seem to help.
public List<PGRatingResponse> collatePGRatingsbyVendor(List<PGRatingConfig> pgRatingSansPgname, List<Vendor> vendors) {
return
pgRatingSansPgname.stream().map(o1 -> {
vendors.stream()
.filter(o2 -> o2.getVendorId().equals(o1.getVendorId()))
.findAny();
return new PGRatingResponse(
o1.getVendorId(),
vendors.stream()
.filter(o ->
o.getVendorId().equals(o1.getVendorId())
&& o.getVendorId()!=null)
.findFirst()
.get()
.getVendorName(),
o1.getRating()
.stream().map(o ->
new RatingResponse(
pgLookupTable().getOrDefault(
o.getPgId()==null?"":o.getPgId(),
"Default"),
o.getPgId()==null?"":o.getPgId(),
o.getValue()))
.collect(Collectors.toList()));
}).collect(Collectors.toList());
}
The inner return statement in the lambda expression is the line number where the stack trace points to.
I'm still getting this exception:
java.lang.NullPointerException] with error Id, error code and message [[com.service.configuration.PGRatingConfigService.lambda$collatePGRatingsbyVendor$2(PGRatingConfigService.java:50),java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195), java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655), java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484), java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474), java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913), java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234), java.base
even when I made changes to this line:
return new PGRatingResponse(o1.getVendorId(), "Default",/*vendors.stream().filter(o -> o.getVendorId()!=null && o.getVendorId().equals(o1.getVendorId())).findFirst().get().getVendorName(),*/ o1.getRating().stream().map(o -> new RatingResponse(pgLookupTable().getOrDefault(o.getPgId()==null?"":o.getPgId(), "Default"), o.getPgId()==null?"":o.getPgId(), o.getValue()==null?0.0:o.getValue())).collect(Collectors.toList()));